| 1 | /* |
| 2 | * Copyright (c) 2018, 2019, Red Hat, Inc. All rights reserved. |
| 3 | * |
| 4 | * This code is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of the GNU General Public License version 2 only, as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 11 | * version 2 for more details (a copy is included in the LICENSE file that |
| 12 | * accompanied this code). |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License version |
| 15 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | * |
| 18 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 19 | * or visit www.oracle.com if you need additional information or have any |
| 20 | * questions. |
| 21 | * |
| 22 | */ |
| 23 | #ifndef SHARE_GC_SHARED_OWSTTASKTERMINATOR_HPP |
| 24 | #define SHARE_GC_SHARED_OWSTTASKTERMINATOR_HPP |
| 25 | |
| 26 | #include "gc/shared/taskqueue.hpp" |
| 27 | #include "runtime/mutex.hpp" |
| 28 | #include "runtime/thread.hpp" |
| 29 | |
| 30 | /* |
| 31 | * OWST stands for Optimized Work Stealing Threads |
| 32 | * |
| 33 | * This is an enhanced implementation of Google's work stealing |
| 34 | * protocol, which is described in the paper: |
| 35 | * "Wessam Hassanein. 2016. Understanding and improving JVM GC work |
| 36 | * stealing at the data center scale. In Proceedings of the 2016 ACM |
| 37 | * SIGPLAN International Symposium on Memory Management (ISMM 2016). ACM, |
| 38 | * New York, NY, USA, 46-54. DOI: https://doi.org/10.1145/2926697.2926706" |
| 39 | * |
| 40 | * Instead of a dedicated spin-master, our implementation will let spin-master relinquish |
| 41 | * the role before it goes to sleep/wait, allowing newly arrived threads to compete for the role. |
| 42 | * The intention of above enhancement is to reduce spin-master's latency on detecting new tasks |
| 43 | * for stealing and termination condition. |
| 44 | */ |
| 45 | |
| 46 | class OWSTTaskTerminator: public ParallelTaskTerminator { |
| 47 | private: |
| 48 | Monitor* _blocker; |
| 49 | Thread* _spin_master; |
| 50 | |
| 51 | public: |
| 52 | OWSTTaskTerminator(uint n_threads, TaskQueueSetSuper* queue_set) : |
| 53 | ParallelTaskTerminator(n_threads, queue_set), _spin_master(NULL) { |
| 54 | _blocker = new Monitor(Mutex::leaf, "OWSTTaskTerminator" , false, Monitor::_safepoint_check_never); |
| 55 | } |
| 56 | |
| 57 | virtual ~OWSTTaskTerminator() { |
| 58 | assert(_spin_master == NULL, "Should have been reset" ); |
| 59 | assert(_blocker != NULL, "Can not be NULL" ); |
| 60 | delete _blocker; |
| 61 | } |
| 62 | |
| 63 | bool offer_termination(TerminatorTerminator* terminator); |
| 64 | |
| 65 | protected: |
| 66 | // If should exit current termination protocol |
| 67 | virtual bool exit_termination(size_t tasks, TerminatorTerminator* terminator); |
| 68 | |
| 69 | private: |
| 70 | size_t tasks_in_queue_set() { return _queue_set->tasks(); } |
| 71 | |
| 72 | /* |
| 73 | * Perform spin-master task. |
| 74 | * Return true if termination condition is detected, otherwise return false |
| 75 | */ |
| 76 | bool do_spin_master_work(TerminatorTerminator* terminator); |
| 77 | }; |
| 78 | |
| 79 | |
| 80 | #endif // SHARE_GC_SHARED_OWSTTASKTERMINATOR_HPP |
| 81 | |