src/hotspot/share/gc/cms/concurrentMarkSweepGeneration.cpp
changeset 52905 bec57b4a6d69
parent 52904 d2f118d3f8e7
child 53536 482109fae02b
equal deleted inserted replaced
52904:d2f118d3f8e7 52905:bec57b4a6d69
    53 #include "gc/shared/gcTraceTime.inline.hpp"
    53 #include "gc/shared/gcTraceTime.inline.hpp"
    54 #include "gc/shared/genCollectedHeap.hpp"
    54 #include "gc/shared/genCollectedHeap.hpp"
    55 #include "gc/shared/genOopClosures.inline.hpp"
    55 #include "gc/shared/genOopClosures.inline.hpp"
    56 #include "gc/shared/isGCActiveMark.hpp"
    56 #include "gc/shared/isGCActiveMark.hpp"
    57 #include "gc/shared/oopStorageParState.hpp"
    57 #include "gc/shared/oopStorageParState.hpp"
       
    58 #include "gc/shared/owstTaskTerminator.hpp"
    58 #include "gc/shared/referencePolicy.hpp"
    59 #include "gc/shared/referencePolicy.hpp"
    59 #include "gc/shared/referenceProcessorPhaseTimes.hpp"
    60 #include "gc/shared/referenceProcessorPhaseTimes.hpp"
    60 #include "gc/shared/space.inline.hpp"
    61 #include "gc/shared/space.inline.hpp"
    61 #include "gc/shared/strongRootsScope.hpp"
    62 #include "gc/shared/strongRootsScope.hpp"
    62 #include "gc/shared/taskqueue.inline.hpp"
    63 #include "gc/shared/taskqueue.inline.hpp"
  2980 }
  2981 }
  2981 
  2982 
  2982 // Forward decl
  2983 // Forward decl
  2983 class CMSConcMarkingTask;
  2984 class CMSConcMarkingTask;
  2984 
  2985 
  2985 class CMSConcMarkingTerminator: public ParallelTaskTerminator {
  2986 class CMSConcMarkingParallelTerminator: public ParallelTaskTerminator {
  2986   CMSCollector*       _collector;
  2987   CMSCollector*       _collector;
  2987   CMSConcMarkingTask* _task;
  2988   CMSConcMarkingTask* _task;
  2988  public:
  2989  public:
  2989   virtual void yield();
  2990   virtual void yield();
  2990 
  2991 
  2991   // "n_threads" is the number of threads to be terminated.
  2992   // "n_threads" is the number of threads to be terminated.
  2992   // "queue_set" is a set of work queues of other threads.
  2993   // "queue_set" is a set of work queues of other threads.
  2993   // "collector" is the CMS collector associated with this task terminator.
  2994   // "collector" is the CMS collector associated with this task terminator.
  2994   // "yield" indicates whether we need the gang as a whole to yield.
  2995   // "yield" indicates whether we need the gang as a whole to yield.
  2995   CMSConcMarkingTerminator(int n_threads, TaskQueueSetSuper* queue_set, CMSCollector* collector) :
  2996   CMSConcMarkingParallelTerminator(int n_threads, TaskQueueSetSuper* queue_set, CMSCollector* collector) :
  2996     ParallelTaskTerminator(n_threads, queue_set),
  2997     ParallelTaskTerminator(n_threads, queue_set),
  2997     _collector(collector) { }
  2998     _collector(collector) { }
  2998 
  2999 
  2999   void set_task(CMSConcMarkingTask* task) {
  3000   void set_task(CMSConcMarkingTask* task) {
  3000     _task = task;
  3001     _task = task;
  3001   }
  3002   }
       
  3003 };
       
  3004 
       
  3005 class CMSConcMarkingOWSTTerminator: public OWSTTaskTerminator {
       
  3006   CMSCollector*       _collector;
       
  3007   CMSConcMarkingTask* _task;
       
  3008  public:
       
  3009   virtual void yield();
       
  3010 
       
  3011   // "n_threads" is the number of threads to be terminated.
       
  3012   // "queue_set" is a set of work queues of other threads.
       
  3013   // "collector" is the CMS collector associated with this task terminator.
       
  3014   // "yield" indicates whether we need the gang as a whole to yield.
       
  3015   CMSConcMarkingOWSTTerminator(int n_threads, TaskQueueSetSuper* queue_set, CMSCollector* collector) :
       
  3016     OWSTTaskTerminator(n_threads, queue_set),
       
  3017     _collector(collector) { }
       
  3018 
       
  3019   void set_task(CMSConcMarkingTask* task) {
       
  3020     _task = task;
       
  3021   }
       
  3022 };
       
  3023 
       
  3024 class CMSConcMarkingTaskTerminator {
       
  3025  private:
       
  3026   ParallelTaskTerminator* _term;
       
  3027  public:
       
  3028   CMSConcMarkingTaskTerminator(int n_threads, TaskQueueSetSuper* queue_set, CMSCollector* collector) {
       
  3029     if (UseOWSTTaskTerminator) {
       
  3030       _term = new CMSConcMarkingOWSTTerminator(n_threads, queue_set, collector);
       
  3031     } else {
       
  3032       _term = new CMSConcMarkingParallelTerminator(n_threads, queue_set, collector);
       
  3033     }
       
  3034   }
       
  3035   ~CMSConcMarkingTaskTerminator() {
       
  3036     assert(_term != NULL, "Must not be NULL");
       
  3037     delete _term;
       
  3038   }
       
  3039 
       
  3040   void set_task(CMSConcMarkingTask* task);
       
  3041   ParallelTaskTerminator* terminator() const { return _term; }
  3002 };
  3042 };
  3003 
  3043 
  3004 class CMSConcMarkingTerminatorTerminator: public TerminatorTerminator {
  3044 class CMSConcMarkingTerminatorTerminator: public TerminatorTerminator {
  3005   CMSConcMarkingTask* _task;
  3045   CMSConcMarkingTask* _task;
  3006  public:
  3046  public:
  3026 
  3066 
  3027   // The per thread work queues, available here for stealing
  3067   // The per thread work queues, available here for stealing
  3028   OopTaskQueueSet*  _task_queues;
  3068   OopTaskQueueSet*  _task_queues;
  3029 
  3069 
  3030   // Termination (and yielding) support
  3070   // Termination (and yielding) support
  3031   CMSConcMarkingTerminator _term;
  3071   CMSConcMarkingTaskTerminator       _term;
  3032   CMSConcMarkingTerminatorTerminator _term_term;
  3072   CMSConcMarkingTerminatorTerminator _term_term;
  3033 
  3073 
  3034  public:
  3074  public:
  3035   CMSConcMarkingTask(CMSCollector* collector,
  3075   CMSConcMarkingTask(CMSCollector* collector,
  3036                  CompactibleFreeListSpace* cms_space,
  3076                  CompactibleFreeListSpace* cms_space,
  3056 
  3096 
  3057   OopTaskQueue* work_queue(int i) { return task_queues()->queue(i); }
  3097   OopTaskQueue* work_queue(int i) { return task_queues()->queue(i); }
  3058 
  3098 
  3059   HeapWord* volatile* global_finger_addr() { return &_global_finger; }
  3099   HeapWord* volatile* global_finger_addr() { return &_global_finger; }
  3060 
  3100 
  3061   CMSConcMarkingTerminator* terminator() { return &_term; }
  3101   ParallelTaskTerminator* terminator() { return _term.terminator(); }
  3062 
  3102 
  3063   virtual void set_for_termination(uint active_workers) {
  3103   virtual void set_for_termination(uint active_workers) {
  3064     terminator()->reset_for_reuse(active_workers);
  3104     terminator()->reset_for_reuse(active_workers);
  3065   }
  3105   }
  3066 
  3106 
  3074   bool result() { return _result; }
  3114   bool result() { return _result; }
  3075 
  3115 
  3076   void reset(HeapWord* ra) {
  3116   void reset(HeapWord* ra) {
  3077     assert(_global_finger >= _cms_space->end(),  "Postcondition of ::work(i)");
  3117     assert(_global_finger >= _cms_space->end(),  "Postcondition of ::work(i)");
  3078     _restart_addr = _global_finger = ra;
  3118     _restart_addr = _global_finger = ra;
  3079     _term.reset_for_reuse();
  3119     _term.terminator()->reset_for_reuse();
  3080   }
  3120   }
  3081 
  3121 
  3082   static bool get_work_from_overflow_stack(CMSMarkStack* ovflw_stk,
  3122   static bool get_work_from_overflow_stack(CMSMarkStack* ovflw_stk,
  3083                                            OopTaskQueue* work_q);
  3123                                            OopTaskQueue* work_q);
  3084 
  3124 
  3095   // because we want terminating threads to yield only if the task
  3135   // because we want terminating threads to yield only if the task
  3096   // is already in the midst of yielding, which happens only after at least one
  3136   // is already in the midst of yielding, which happens only after at least one
  3097   // thread has yielded.
  3137   // thread has yielded.
  3098 }
  3138 }
  3099 
  3139 
  3100 void CMSConcMarkingTerminator::yield() {
  3140 void CMSConcMarkingParallelTerminator::yield() {
  3101   if (_task->should_yield()) {
  3141   if (_task->should_yield()) {
  3102     _task->yield();
  3142     _task->yield();
  3103   } else {
  3143   } else {
  3104     ParallelTaskTerminator::yield();
  3144     ParallelTaskTerminator::yield();
       
  3145   }
       
  3146 }
       
  3147 
       
  3148 void CMSConcMarkingOWSTTerminator::yield() {
       
  3149   if (_task->should_yield()) {
       
  3150     _task->yield();
       
  3151   } else {
       
  3152     OWSTTaskTerminator::yield();
       
  3153   }
       
  3154 }
       
  3155 
       
  3156 void CMSConcMarkingTaskTerminator::set_task(CMSConcMarkingTask* task) {
       
  3157   if (UseOWSTTaskTerminator) {
       
  3158     ((CMSConcMarkingOWSTTerminator*)_term)->set_task(task);
       
  3159   } else {
       
  3160     ((CMSConcMarkingParallelTerminator*)_term)->set_task(task);
  3105   }
  3161   }
  3106 }
  3162 }
  3107 
  3163 
  3108 ////////////////////////////////////////////////////////////////
  3164 ////////////////////////////////////////////////////////////////
  3109 // Concurrent Marking Algorithm Sketch
  3165 // Concurrent Marking Algorithm Sketch
  4291 class CMSParRemarkTask: public CMSParMarkTask {
  4347 class CMSParRemarkTask: public CMSParMarkTask {
  4292   CompactibleFreeListSpace* _cms_space;
  4348   CompactibleFreeListSpace* _cms_space;
  4293 
  4349 
  4294   // The per-thread work queues, available here for stealing.
  4350   // The per-thread work queues, available here for stealing.
  4295   OopTaskQueueSet*       _task_queues;
  4351   OopTaskQueueSet*       _task_queues;
  4296   ParallelTaskTerminator _term;
  4352   TaskTerminator         _term;
  4297   StrongRootsScope*      _strong_roots_scope;
  4353   StrongRootsScope*      _strong_roots_scope;
  4298 
  4354 
  4299  public:
  4355  public:
  4300   // A value of 0 passed to n_workers will cause the number of
  4356   // A value of 0 passed to n_workers will cause the number of
  4301   // workers to be taken from the active workers in the work gang.
  4357   // workers to be taken from the active workers in the work gang.
  4313 
  4369 
  4314   OopTaskQueueSet* task_queues() { return _task_queues; }
  4370   OopTaskQueueSet* task_queues() { return _task_queues; }
  4315 
  4371 
  4316   OopTaskQueue* work_queue(int i) { return task_queues()->queue(i); }
  4372   OopTaskQueue* work_queue(int i) { return task_queues()->queue(i); }
  4317 
  4373 
  4318   ParallelTaskTerminator* terminator() { return &_term; }
  4374   ParallelTaskTerminator* terminator() { return _term.terminator(); }
  4319   uint n_workers() { return _n_workers; }
  4375   uint n_workers() { return _n_workers; }
  4320 
  4376 
  4321   void work(uint worker_id);
  4377   void work(uint worker_id);
  4322 
  4378 
  4323  private:
  4379  private:
  5001 ////////////////////////////////////////////////////////
  5057 ////////////////////////////////////////////////////////
  5002 // Parallel Reference Processing Task Proxy Class
  5058 // Parallel Reference Processing Task Proxy Class
  5003 ////////////////////////////////////////////////////////
  5059 ////////////////////////////////////////////////////////
  5004 class AbstractGangTaskWOopQueues : public AbstractGangTask {
  5060 class AbstractGangTaskWOopQueues : public AbstractGangTask {
  5005   OopTaskQueueSet*       _queues;
  5061   OopTaskQueueSet*       _queues;
  5006   ParallelTaskTerminator _terminator;
  5062   TaskTerminator         _terminator;
  5007  public:
  5063  public:
  5008   AbstractGangTaskWOopQueues(const char* name, OopTaskQueueSet* queues, uint n_threads) :
  5064   AbstractGangTaskWOopQueues(const char* name, OopTaskQueueSet* queues, uint n_threads) :
  5009     AbstractGangTask(name), _queues(queues), _terminator(n_threads, _queues) {}
  5065     AbstractGangTask(name), _queues(queues), _terminator(n_threads, _queues) {}
  5010   ParallelTaskTerminator* terminator() { return &_terminator; }
  5066   ParallelTaskTerminator* terminator() { return _terminator.terminator(); }
  5011   OopTaskQueueSet* queues() { return _queues; }
  5067   OopTaskQueueSet* queues() { return _queues; }
  5012 };
  5068 };
  5013 
  5069 
  5014 class CMSRefProcTaskProxy: public AbstractGangTaskWOopQueues {
  5070 class CMSRefProcTaskProxy: public AbstractGangTaskWOopQueues {
  5015   typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask;
  5071   typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask;