342N/A/*
1879N/A * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
342N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
342N/A *
342N/A * This code is free software; you can redistribute it and/or modify it
342N/A * under the terms of the GNU General Public License version 2 only, as
342N/A * published by the Free Software Foundation.
342N/A *
342N/A * This code is distributed in the hope that it will be useful, but WITHOUT
342N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
342N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
342N/A * version 2 for more details (a copy is included in the LICENSE file that
342N/A * accompanied this code).
342N/A *
342N/A * You should have received a copy of the GNU General Public License version
342N/A * 2 along with this work; if not, write to the Free Software Foundation,
342N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
342N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
342N/A *
342N/A */
342N/A
1879N/A#ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_CONCURRENTGCTHREAD_HPP
1879N/A#define SHARE_VM_GC_IMPLEMENTATION_SHARED_CONCURRENTGCTHREAD_HPP
1879N/A
1879N/A#ifndef SERIALGC
1879N/A#include "runtime/thread.hpp"
1879N/A#endif
1879N/A
342N/Aclass VoidClosure;
342N/A
342N/A// A SuspendibleThreadSet is (obviously) a set of threads that can be
342N/A// suspended. A thread can join and later leave the set, and periodically
342N/A// yield. If some thread (not in the set) requests, via suspend_all, that
342N/A// the threads be suspended, then the requesting thread is blocked until
342N/A// all the threads in the set have yielded or left the set. (Threads may
342N/A// not enter the set when an attempted suspension is in progress.) The
342N/A// suspending thread later calls resume_all, allowing the suspended threads
342N/A// to continue.
342N/A
342N/Aclass SuspendibleThreadSet {
342N/A Monitor* _m;
342N/A int _async;
342N/A bool _async_stop;
342N/A int _async_stopped;
342N/A bool _initialized;
342N/A double _suspend_all_start;
342N/A
342N/A void initialize_work();
342N/A
342N/A public:
342N/A SuspendibleThreadSet() : _initialized(false) {}
342N/A
342N/A // Add the current thread to the set. May block if a suspension
342N/A // is in progress.
342N/A void join();
342N/A // Removes the current thread from the set.
342N/A void leave();
342N/A // Returns "true" iff an suspension is in progress.
342N/A bool should_yield() { return _async_stop; }
342N/A // Suspends the current thread if a suspension is in progress (for
342N/A // the duration of the suspension.)
342N/A void yield(const char* id);
342N/A // Return when all threads in the set are suspended.
342N/A void suspend_all();
342N/A // Allow suspended threads to resume.
342N/A void resume_all();
342N/A // Redundant initializations okay.
342N/A void initialize() {
342N/A // Double-check dirty read idiom.
342N/A if (!_initialized) initialize_work();
342N/A }
342N/A};
342N/A
342N/A
342N/Aclass ConcurrentGCThread: public NamedThread {
342N/A friend class VMStructs;
342N/A
342N/Aprotected:
794N/A bool _should_terminate;
794N/A bool _has_terminated;
342N/A
342N/A enum CGC_flag_type {
342N/A CGC_nil = 0x0,
342N/A CGC_dont_suspend = 0x1,
342N/A CGC_CGC_safepoint = 0x2,
342N/A CGC_VM_safepoint = 0x4
342N/A };
342N/A
342N/A static int _CGC_flag;
342N/A
342N/A static bool CGC_flag_is_set(int b) { return (_CGC_flag & b) != 0; }
342N/A static int set_CGC_flag(int b) { return _CGC_flag |= b; }
342N/A static int reset_CGC_flag(int b) { return _CGC_flag &= ~b; }
342N/A
342N/A // All instances share this one set.
342N/A static SuspendibleThreadSet _sts;
342N/A
342N/A // Create and start the thread (setting it's priority high.)
342N/A void create_and_start();
342N/A
342N/A // Do initialization steps in the thread: record stack base and size,
342N/A // init thread local storage, set JNI handle block.
342N/A void initialize_in_thread();
342N/A
342N/A // Wait until Universe::is_fully_initialized();
342N/A void wait_for_universe_init();
342N/A
342N/A // Record that the current thread is terminating, and will do more
342N/A // concurrent work.
342N/A void terminate();
342N/A
342N/Apublic:
342N/A // Constructor
342N/A
342N/A ConcurrentGCThread();
342N/A ~ConcurrentGCThread() {} // Exists to call NamedThread destructor.
342N/A
342N/A // Tester
342N/A bool is_ConcurrentGC_thread() const { return true; }
342N/A
342N/A static void safepoint_synchronize();
342N/A static void safepoint_desynchronize();
342N/A
342N/A // All overridings should probably do _sts::yield, but we allow
342N/A // overriding for distinguished debugging messages. Default is to do
342N/A // nothing.
342N/A virtual void yield() {}
342N/A
342N/A bool should_yield() { return _sts.should_yield(); }
342N/A
342N/A // they are prefixed by sts since there are already yield() and
342N/A // should_yield() (non-static) methods in this class and it was an
342N/A // easy way to differentiate them.
342N/A static void stsYield(const char* id);
342N/A static bool stsShouldYield();
342N/A static void stsJoin();
342N/A static void stsLeave();
342N/A
342N/A};
342N/A
342N/A// The SurrogateLockerThread is used by concurrent GC threads for
342N/A// manipulating Java monitors, in particular, currently for
342N/A// manipulating the pending_list_lock. XXX
342N/Aclass SurrogateLockerThread: public JavaThread {
342N/A friend class VMStructs;
342N/A public:
342N/A enum SLT_msg_type {
342N/A empty = 0, // no message
342N/A acquirePLL, // acquire pending list lock
342N/A releaseAndNotifyPLL // notify and release pending list lock
342N/A };
342N/A private:
342N/A // the following are shared with the CMSThread
342N/A SLT_msg_type _buffer; // communication buffer
342N/A Monitor _monitor; // monitor controlling buffer
342N/A BasicLock _basicLock; // used for PLL locking
342N/A
342N/A public:
342N/A static SurrogateLockerThread* make(TRAPS);
342N/A
342N/A SurrogateLockerThread();
342N/A
342N/A bool is_hidden_from_external_view() const { return true; }
342N/A
342N/A void loop(); // main method
342N/A
342N/A void manipulatePLL(SLT_msg_type msg);
342N/A
342N/A};
1879N/A
1879N/A#endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_CONCURRENTGCTHREAD_HPP