src/hotspot/share/gc/shared/concurrentGCPhaseManager.cpp
changeset 54623 1126f0607c70
parent 47216 71c04702a3d5
equal deleted inserted replaced
54622:a8dcacf95bff 54623:1126f0607c70
     1 /*
     1 /*
     2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2017, 2019, 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.
    48   _stack(stack)
    48   _stack(stack)
    49 {
    49 {
    50   assert_ConcurrentGC_thread();
    50   assert_ConcurrentGC_thread();
    51   assert_not_enter_unconstrained(phase);
    51   assert_not_enter_unconstrained(phase);
    52   assert(stack != NULL, "precondition");
    52   assert(stack != NULL, "precondition");
    53   MonitorLockerEx ml(CGCPhaseManager_lock, Mutex::_no_safepoint_check_flag);
    53   MonitorLocker ml(CGCPhaseManager_lock, Mutex::_no_safepoint_check_flag);
    54   if (stack->_top != NULL) {
    54   if (stack->_top != NULL) {
    55     assert(stack->_top->_active, "precondition");
    55     assert(stack->_top->_active, "precondition");
    56     _prev = stack->_top;
    56     _prev = stack->_top;
    57   }
    57   }
    58   stack->_top = this;
    58   stack->_top = this;
    59   ml.notify_all();
    59   ml.notify_all();
    60 }
    60 }
    61 
    61 
    62 ConcurrentGCPhaseManager::~ConcurrentGCPhaseManager() {
    62 ConcurrentGCPhaseManager::~ConcurrentGCPhaseManager() {
    63   assert_ConcurrentGC_thread();
    63   assert_ConcurrentGC_thread();
    64   MonitorLockerEx ml(CGCPhaseManager_lock, Mutex::_no_safepoint_check_flag);
    64   MonitorLocker ml(CGCPhaseManager_lock, Mutex::_no_safepoint_check_flag);
    65   assert_manager_is_tos(this, _stack, "This");
    65   assert_manager_is_tos(this, _stack, "This");
    66   wait_when_requested_impl();
    66   wait_when_requested_impl();
    67   _stack->_top = _prev;
    67   _stack->_top = _prev;
    68   ml.notify_all();
    68   ml.notify_all();
    69 }
    69 }
    70 
    70 
    71 bool ConcurrentGCPhaseManager::is_requested() const {
    71 bool ConcurrentGCPhaseManager::is_requested() const {
    72   assert_ConcurrentGC_thread();
    72   assert_ConcurrentGC_thread();
    73   MonitorLockerEx ml(CGCPhaseManager_lock, Mutex::_no_safepoint_check_flag);
    73   MonitorLocker ml(CGCPhaseManager_lock, Mutex::_no_safepoint_check_flag);
    74   assert_manager_is_tos(this, _stack, "This");
    74   assert_manager_is_tos(this, _stack, "This");
    75   return _active && (_stack->_requested_phase == _phase);
    75   return _active && (_stack->_requested_phase == _phase);
    76 }
    76 }
    77 
    77 
    78 bool ConcurrentGCPhaseManager::wait_when_requested_impl() const {
    78 bool ConcurrentGCPhaseManager::wait_when_requested_impl() const {
    79   assert_ConcurrentGC_thread();
    79   assert_ConcurrentGC_thread();
    80   assert_lock_strong(CGCPhaseManager_lock);
    80   assert_lock_strong(CGCPhaseManager_lock);
    81   bool waited = false;
    81   bool waited = false;
    82   while (_active && (_stack->_requested_phase == _phase)) {
    82   while (_active && (_stack->_requested_phase == _phase)) {
    83     waited = true;
    83     waited = true;
    84     CGCPhaseManager_lock->wait(Mutex::_no_safepoint_check_flag);
    84     CGCPhaseManager_lock->wait_without_safepoint_check();
    85   }
    85   }
    86   return waited;
    86   return waited;
    87 }
    87 }
    88 
    88 
    89 bool ConcurrentGCPhaseManager::wait_when_requested() const {
    89 bool ConcurrentGCPhaseManager::wait_when_requested() const {
    90   assert_ConcurrentGC_thread();
    90   assert_ConcurrentGC_thread();
    91   MonitorLockerEx ml(CGCPhaseManager_lock, Mutex::_no_safepoint_check_flag);
    91   MonitorLocker ml(CGCPhaseManager_lock, Mutex::_no_safepoint_check_flag);
    92   assert_manager_is_tos(this, _stack, "This");
    92   assert_manager_is_tos(this, _stack, "This");
    93   return wait_when_requested_impl();
    93   return wait_when_requested_impl();
    94 }
    94 }
    95 
    95 
    96 void ConcurrentGCPhaseManager::set_phase(int phase, bool force) {
    96 void ConcurrentGCPhaseManager::set_phase(int phase, bool force) {
    97   assert_ConcurrentGC_thread();
    97   assert_ConcurrentGC_thread();
    98   assert_not_enter_unconstrained(phase);
    98   assert_not_enter_unconstrained(phase);
    99   MonitorLockerEx ml(CGCPhaseManager_lock, Mutex::_no_safepoint_check_flag);
    99   MonitorLocker ml(CGCPhaseManager_lock, Mutex::_no_safepoint_check_flag);
   100   assert_manager_is_tos(this, _stack, "This");
   100   assert_manager_is_tos(this, _stack, "This");
   101   if (!force) wait_when_requested_impl();
   101   if (!force) wait_when_requested_impl();
   102   _phase = phase;
   102   _phase = phase;
   103   ml.notify_all();
   103   ml.notify_all();
   104 }
   104 }
   105 
   105 
   106 void ConcurrentGCPhaseManager::deactivate() {
   106 void ConcurrentGCPhaseManager::deactivate() {
   107   assert_ConcurrentGC_thread();
   107   assert_ConcurrentGC_thread();
   108   MonitorLockerEx ml(CGCPhaseManager_lock, Mutex::_no_safepoint_check_flag);
   108   MonitorLocker ml(CGCPhaseManager_lock, Mutex::_no_safepoint_check_flag);
   109   assert_manager_is_tos(this, _stack, "This");
   109   assert_manager_is_tos(this, _stack, "This");
   110   _active = false;
   110   _active = false;
   111   ml.notify_all();
   111   ml.notify_all();
   112 }
   112 }
   113 
   113 
   114 bool ConcurrentGCPhaseManager::wait_for_phase(int phase, Stack* stack) {
   114 bool ConcurrentGCPhaseManager::wait_for_phase(int phase, Stack* stack) {
   115   assert(Thread::current()->is_Java_thread(), "precondition");
   115   assert(Thread::current()->is_Java_thread(), "precondition");
   116   assert(stack != NULL, "precondition");
   116   assert(stack != NULL, "precondition");
   117   MonitorLockerEx ml(CGCPhaseManager_lock);
   117   MonitorLocker ml(CGCPhaseManager_lock);
   118   // Update request and notify service of change.
   118   // Update request and notify service of change.
   119   if (stack->_requested_phase != phase) {
   119   if (stack->_requested_phase != phase) {
   120     stack->_requested_phase = phase;
   120     stack->_requested_phase = phase;
   121     ml.notify_all();
   121     ml.notify_all();
   122   }
   122   }