/* * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. * */ #ifndef SHARE_VM_RUNTIME_GLOBALSYNCHRONIZER_HPP #define SHARE_VM_RUNTIME_GLOBALSYNCHRONIZER_HPP #include "memory/allocation.hpp" class JavaThread; class ThreadClosure; // This class is used to coordinate global synchronization among mutator threads. // It may be used in a lazy asynchronous way to reduce global overheads of the mechanism. class GlobalSynchronizer { friend class GSHasFinishedThreadClosure; public: enum UrgencyLevel { UrgencyLevel1, // Hope for runtime to respond willingly UrgencyLevel2, // Arm thread-local yieldpoints for forced handshaking UrgencyLevel3, // Force running threads to yield to complete the handshake. // May also check if threads are ONPROC when this information is available UrgencyLevel4, // Enforce global synchronization to finish with whatever means necessary // and available on the platform, including IPI UrgencyLevelMax = UrgencyLevel4 }; private: UrgencyLevel _current_urgency; UrgencyLevel _max_urgency; int _threads_left; int _local_serialized_memory_version; private: void threads_do(ThreadClosure *cl); private: static volatile int _global_serialized_memory_version; static volatile int _latest_global_serialized_memory_version; public: static int global_serialized_memory_version(); public: virtual ~GlobalSynchronizer(); GlobalSynchronizer(UrgencyLevel start_urgency = UrgencyLevel1, UrgencyLevel max_urgency = UrgencyLevel4); // Starts the synchronization process void start_synchronizing(); bool increase_urgency(); void maximize_urgency(); bool try_synchronize(); // For less urgent more scalable synchronization void synchronize(); // For aggressive blocking synchronization }; template class SynchronizerObj: public GlobalSynchronizer, public CHeapObj { public: SynchronizerObj(UrgencyLevel start_urgency = UrgencyLevel1, UrgencyLevel max_urgency = UrgencyLevel4) : GlobalSynchronizer(start_urgency, max_urgency) {} }; #endif // SHARE_VM_RUNTIME_GLOBALSYNCHRONIZER_HPP