0N/A/*
1879N/A * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/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.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_RUNTIME_VMTHREAD_HPP
1879N/A#define SHARE_VM_RUNTIME_VMTHREAD_HPP
1879N/A
1879N/A#include "runtime/perfData.hpp"
1879N/A#include "runtime/vm_operations.hpp"
1879N/A#ifdef TARGET_OS_FAMILY_linux
1879N/A# include "thread_linux.inline.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_OS_FAMILY_solaris
1879N/A# include "thread_solaris.inline.hpp"
1879N/A#endif
1879N/A#ifdef TARGET_OS_FAMILY_windows
1879N/A# include "thread_windows.inline.hpp"
1879N/A#endif
2796N/A#ifdef TARGET_OS_FAMILY_bsd
2796N/A# include "thread_bsd.inline.hpp"
2796N/A#endif
1879N/A
0N/A//
0N/A// Prioritized queue of VM operations.
0N/A//
0N/A// Encapsulates both queue management and
0N/A// and priority policy
0N/A//
3863N/Aclass VMOperationQueue : public CHeapObj<mtInternal> {
0N/A private:
0N/A enum Priorities {
0N/A SafepointPriority, // Highest priority (operation executed at a safepoint)
0N/A MediumPriority, // Medium priority
0N/A nof_priorities
0N/A };
0N/A
0N/A // We maintain a doubled linked list, with explicit count.
0N/A int _queue_length[nof_priorities];
0N/A int _queue_counter;
0N/A VM_Operation* _queue [nof_priorities];
0N/A // we also allow the vmThread to register the ops it has drained so we
0N/A // can scan them from oops_do
0N/A VM_Operation* _drain_list;
0N/A
0N/A // Double-linked non-empty list insert.
0N/A void insert(VM_Operation* q,VM_Operation* n);
0N/A void unlink(VM_Operation* q);
0N/A
0N/A // Basic queue manipulation
0N/A bool queue_empty (int prio);
0N/A void queue_add_front (int prio, VM_Operation *op);
0N/A void queue_add_back (int prio, VM_Operation *op);
0N/A VM_Operation* queue_remove_front(int prio);
0N/A void queue_oops_do(int queue, OopClosure* f);
0N/A void drain_list_oops_do(OopClosure* f);
0N/A VM_Operation* queue_drain(int prio);
0N/A // lock-free query: may return the wrong answer but must not break
0N/A bool queue_peek(int prio) { return _queue_length[prio] > 0; }
0N/A
0N/A public:
0N/A VMOperationQueue();
0N/A
0N/A // Highlevel operations. Encapsulates policy
0N/A bool add(VM_Operation *op);
0N/A VM_Operation* remove_next(); // Returns next or null
0N/A VM_Operation* remove_next_at_safepoint_priority() { return queue_remove_front(SafepointPriority); }
0N/A VM_Operation* drain_at_safepoint_priority() { return queue_drain(SafepointPriority); }
0N/A void set_drain_list(VM_Operation* list) { _drain_list = list; }
0N/A bool peek_at_safepoint_priority() { return queue_peek(SafepointPriority); }
0N/A
0N/A // GC support
0N/A void oops_do(OopClosure* f);
0N/A
0N/A void verify_queue(int prio) PRODUCT_RETURN;
0N/A};
0N/A
0N/A
0N/A//
0N/A// A single VMThread (the primordial thread) spawns all other threads
0N/A// and is itself used by other threads to offload heavy vm operations
0N/A// like scavenge, garbage_collect etc.
0N/A//
0N/A
1119N/Aclass VMThread: public NamedThread {
0N/A private:
0N/A static ThreadPriority _current_priority;
0N/A
0N/A static bool _should_terminate;
0N/A static bool _terminated;
0N/A static Monitor * _terminate_lock;
0N/A static PerfCounter* _perf_accumulated_vm_operation_time;
0N/A
0N/A void evaluate_operation(VM_Operation* op);
0N/A public:
0N/A // Constructor
0N/A VMThread();
0N/A
0N/A // Tester
0N/A bool is_VM_thread() const { return true; }
0N/A bool is_GC_thread() const { return true; }
0N/A
0N/A // The ever running loop for the VMThread
0N/A void loop();
0N/A
0N/A // Called to stop the VM thread
0N/A static void wait_for_vm_thread_exit();
0N/A static bool should_terminate() { return _should_terminate; }
0N/A static bool is_terminated() { return _terminated == true; }
0N/A
0N/A // Execution of vm operation
0N/A static void execute(VM_Operation* op);
0N/A
0N/A // Returns the current vm operation if any.
0N/A static VM_Operation* vm_operation() { return _cur_vm_operation; }
0N/A
0N/A // Returns the single instance of VMThread.
0N/A static VMThread* vm_thread() { return _vm_thread; }
0N/A
0N/A // GC support
989N/A void oops_do(OopClosure* f, CodeBlobClosure* cf);
0N/A
0N/A // Debugging
0N/A void print_on(outputStream* st) const;
0N/A void print() const { print_on(tty); }
0N/A void verify();
0N/A
0N/A // Performance measurement
0N/A static PerfCounter* perf_accumulated_vm_operation_time() { return _perf_accumulated_vm_operation_time; }
0N/A
0N/A // Entry for starting vm thread
0N/A virtual void run();
0N/A
0N/A // Creations/Destructions
0N/A static void create();
0N/A static void destroy();
0N/A
0N/A private:
0N/A // VM_Operation support
0N/A static VM_Operation* _cur_vm_operation; // Current VM operation
0N/A static VMOperationQueue* _vm_queue; // Queue (w/ policy) of VM operations
0N/A
0N/A // Pointer to single-instance of VM thread
0N/A static VMThread* _vm_thread;
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_RUNTIME_VMTHREAD_HPP