< prev index next >

src/hotspot/share/gc/shared/concurrentGCPhaseManager.cpp

Print this page




  33 #define assert_not_enter_unconstrained(phase) \
  34   assert((phase) != UNCONSTRAINED_PHASE, "Cannot enter \"unconstrained\" phase")
  35 
  36 #define assert_manager_is_tos(manager, stack, kind)  \
  37   assert((manager) == (stack)->_top, kind " manager is not top of stack")
  38 
  39 ConcurrentGCPhaseManager::Stack::Stack() :
  40   _requested_phase(UNCONSTRAINED_PHASE),
  41   _top(NULL)
  42 { }
  43 
  44 ConcurrentGCPhaseManager::ConcurrentGCPhaseManager(int phase, Stack* stack) :
  45   _phase(phase),
  46   _active(true),
  47   _prev(NULL),
  48   _stack(stack)
  49 {
  50   assert_ConcurrentGC_thread();
  51   assert_not_enter_unconstrained(phase);
  52   assert(stack != NULL, "precondition");
  53   MonitorLockerEx ml(CGCPhaseManager_lock, Mutex::_no_safepoint_check_flag);
  54   if (stack->_top != NULL) {
  55     assert(stack->_top->_active, "precondition");
  56     _prev = stack->_top;
  57   }
  58   stack->_top = this;
  59   ml.notify_all();
  60 }
  61 
  62 ConcurrentGCPhaseManager::~ConcurrentGCPhaseManager() {
  63   assert_ConcurrentGC_thread();
  64   MonitorLockerEx ml(CGCPhaseManager_lock, Mutex::_no_safepoint_check_flag);
  65   assert_manager_is_tos(this, _stack, "This");
  66   wait_when_requested_impl();
  67   _stack->_top = _prev;
  68   ml.notify_all();
  69 }
  70 
  71 bool ConcurrentGCPhaseManager::is_requested() const {
  72   assert_ConcurrentGC_thread();
  73   MonitorLockerEx ml(CGCPhaseManager_lock, Mutex::_no_safepoint_check_flag);
  74   assert_manager_is_tos(this, _stack, "This");
  75   return _active && (_stack->_requested_phase == _phase);
  76 }
  77 
  78 bool ConcurrentGCPhaseManager::wait_when_requested_impl() const {
  79   assert_ConcurrentGC_thread();
  80   assert_lock_strong(CGCPhaseManager_lock);
  81   bool waited = false;
  82   while (_active && (_stack->_requested_phase == _phase)) {
  83     waited = true;

  84     CGCPhaseManager_lock->wait(Mutex::_no_safepoint_check_flag);
  85   }
  86   return waited;
  87 }
  88 
  89 bool ConcurrentGCPhaseManager::wait_when_requested() const {
  90   assert_ConcurrentGC_thread();
  91   MonitorLockerEx ml(CGCPhaseManager_lock, Mutex::_no_safepoint_check_flag);
  92   assert_manager_is_tos(this, _stack, "This");
  93   return wait_when_requested_impl();
  94 }
  95 
  96 void ConcurrentGCPhaseManager::set_phase(int phase, bool force) {
  97   assert_ConcurrentGC_thread();
  98   assert_not_enter_unconstrained(phase);
  99   MonitorLockerEx ml(CGCPhaseManager_lock, Mutex::_no_safepoint_check_flag);
 100   assert_manager_is_tos(this, _stack, "This");
 101   if (!force) wait_when_requested_impl();
 102   _phase = phase;
 103   ml.notify_all();
 104 }
 105 
 106 void ConcurrentGCPhaseManager::deactivate() {
 107   assert_ConcurrentGC_thread();
 108   MonitorLockerEx ml(CGCPhaseManager_lock, Mutex::_no_safepoint_check_flag);
 109   assert_manager_is_tos(this, _stack, "This");
 110   _active = false;
 111   ml.notify_all();
 112 }
 113 
 114 bool ConcurrentGCPhaseManager::wait_for_phase(int phase, Stack* stack) {
 115   assert(Thread::current()->is_Java_thread(), "precondition");
 116   assert(stack != NULL, "precondition");
 117   MonitorLockerEx ml(CGCPhaseManager_lock);
 118   // Update request and notify service of change.
 119   if (stack->_requested_phase != phase) {
 120     stack->_requested_phase = phase;
 121     ml.notify_all();
 122   }
 123 
 124   if (phase == UNCONSTRAINED_PHASE) {
 125     return true;
 126   }
 127 
 128   // Wait until phase or IDLE is active.


  33 #define assert_not_enter_unconstrained(phase) \
  34   assert((phase) != UNCONSTRAINED_PHASE, "Cannot enter \"unconstrained\" phase")
  35 
  36 #define assert_manager_is_tos(manager, stack, kind)  \
  37   assert((manager) == (stack)->_top, kind " manager is not top of stack")
  38 
  39 ConcurrentGCPhaseManager::Stack::Stack() :
  40   _requested_phase(UNCONSTRAINED_PHASE),
  41   _top(NULL)
  42 { }
  43 
  44 ConcurrentGCPhaseManager::ConcurrentGCPhaseManager(int phase, Stack* stack) :
  45   _phase(phase),
  46   _active(true),
  47   _prev(NULL),
  48   _stack(stack)
  49 {
  50   assert_ConcurrentGC_thread();
  51   assert_not_enter_unconstrained(phase);
  52   assert(stack != NULL, "precondition");
  53   MonitorLockerEx ml(CGCPhaseManager_lock);
  54   if (stack->_top != NULL) {
  55     assert(stack->_top->_active, "precondition");
  56     _prev = stack->_top;
  57   }
  58   stack->_top = this;
  59   ml.notify_all();
  60 }
  61 
  62 ConcurrentGCPhaseManager::~ConcurrentGCPhaseManager() {
  63   assert_ConcurrentGC_thread();
  64   MonitorLockerEx ml(CGCPhaseManager_lock);
  65   assert_manager_is_tos(this, _stack, "This");
  66   wait_when_requested_impl();
  67   _stack->_top = _prev;
  68   ml.notify_all();
  69 }
  70 
  71 bool ConcurrentGCPhaseManager::is_requested() const {
  72   assert_ConcurrentGC_thread();
  73   MonitorLockerEx ml(CGCPhaseManager_lock);
  74   assert_manager_is_tos(this, _stack, "This");
  75   return _active && (_stack->_requested_phase == _phase);
  76 }
  77 
  78 bool ConcurrentGCPhaseManager::wait_when_requested_impl() const {
  79   assert_ConcurrentGC_thread();
  80   assert_lock_strong(CGCPhaseManager_lock);
  81   bool waited = false;
  82   while (_active && (_stack->_requested_phase == _phase)) {
  83     waited = true;
  84     // wait safepoint check should be a property of the thread type also.
  85     CGCPhaseManager_lock->wait(Mutex::_no_safepoint_check_flag);
  86   }
  87   return waited;
  88 }
  89 
  90 bool ConcurrentGCPhaseManager::wait_when_requested() const {
  91   assert_ConcurrentGC_thread();
  92   MonitorLockerEx ml(CGCPhaseManager_lock);
  93   assert_manager_is_tos(this, _stack, "This");
  94   return wait_when_requested_impl();
  95 }
  96 
  97 void ConcurrentGCPhaseManager::set_phase(int phase, bool force) {
  98   assert_ConcurrentGC_thread();
  99   assert_not_enter_unconstrained(phase);
 100   MonitorLockerEx ml(CGCPhaseManager_lock);
 101   assert_manager_is_tos(this, _stack, "This");
 102   if (!force) wait_when_requested_impl();
 103   _phase = phase;
 104   ml.notify_all();
 105 }
 106 
 107 void ConcurrentGCPhaseManager::deactivate() {
 108   assert_ConcurrentGC_thread();
 109   MonitorLockerEx ml(CGCPhaseManager_lock);
 110   assert_manager_is_tos(this, _stack, "This");
 111   _active = false;
 112   ml.notify_all();
 113 }
 114 
 115 bool ConcurrentGCPhaseManager::wait_for_phase(int phase, Stack* stack) {
 116   assert(Thread::current()->is_Java_thread(), "precondition");
 117   assert(stack != NULL, "precondition");
 118   MonitorLockerEx ml(CGCPhaseManager_lock);
 119   // Update request and notify service of change.
 120   if (stack->_requested_phase != phase) {
 121     stack->_requested_phase = phase;
 122     ml.notify_all();
 123   }
 124 
 125   if (phase == UNCONSTRAINED_PHASE) {
 126     return true;
 127   }
 128 
 129   // Wait until phase or IDLE is active.
< prev index next >