src/share/vm/runtime/vmThread.hpp

Wed, 06 Jul 2011 13:02:54 -0700

author
jcoomes
date
Wed, 06 Jul 2011 13:02:54 -0700
changeset 2997
bf6481e5f96d
parent 2314
f95d63e2154a
child 3156
f08d439fab8c
permissions
-rw-r--r--

7061225: os::print_cpu_info() should support os-specific data
Reviewed-by: dholmes, never, jwilhelm, kvn

duke@435 1 /*
stefank@2314 2 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_RUNTIME_VMTHREAD_HPP
stefank@2314 26 #define SHARE_VM_RUNTIME_VMTHREAD_HPP
stefank@2314 27
stefank@2314 28 #include "runtime/perfData.hpp"
stefank@2314 29 #include "runtime/vm_operations.hpp"
stefank@2314 30 #ifdef TARGET_OS_FAMILY_linux
stefank@2314 31 # include "thread_linux.inline.hpp"
stefank@2314 32 #endif
stefank@2314 33 #ifdef TARGET_OS_FAMILY_solaris
stefank@2314 34 # include "thread_solaris.inline.hpp"
stefank@2314 35 #endif
stefank@2314 36 #ifdef TARGET_OS_FAMILY_windows
stefank@2314 37 # include "thread_windows.inline.hpp"
stefank@2314 38 #endif
stefank@2314 39
duke@435 40 //
duke@435 41 // Prioritized queue of VM operations.
duke@435 42 //
duke@435 43 // Encapsulates both queue management and
duke@435 44 // and priority policy
duke@435 45 //
duke@435 46 class VMOperationQueue : public CHeapObj {
duke@435 47 private:
duke@435 48 enum Priorities {
duke@435 49 SafepointPriority, // Highest priority (operation executed at a safepoint)
duke@435 50 MediumPriority, // Medium priority
duke@435 51 nof_priorities
duke@435 52 };
duke@435 53
duke@435 54 // We maintain a doubled linked list, with explicit count.
duke@435 55 int _queue_length[nof_priorities];
duke@435 56 int _queue_counter;
duke@435 57 VM_Operation* _queue [nof_priorities];
duke@435 58 // we also allow the vmThread to register the ops it has drained so we
duke@435 59 // can scan them from oops_do
duke@435 60 VM_Operation* _drain_list;
duke@435 61
duke@435 62 // Double-linked non-empty list insert.
duke@435 63 void insert(VM_Operation* q,VM_Operation* n);
duke@435 64 void unlink(VM_Operation* q);
duke@435 65
duke@435 66 // Basic queue manipulation
duke@435 67 bool queue_empty (int prio);
duke@435 68 void queue_add_front (int prio, VM_Operation *op);
duke@435 69 void queue_add_back (int prio, VM_Operation *op);
duke@435 70 VM_Operation* queue_remove_front(int prio);
duke@435 71 void queue_oops_do(int queue, OopClosure* f);
duke@435 72 void drain_list_oops_do(OopClosure* f);
duke@435 73 VM_Operation* queue_drain(int prio);
duke@435 74 // lock-free query: may return the wrong answer but must not break
duke@435 75 bool queue_peek(int prio) { return _queue_length[prio] > 0; }
duke@435 76
duke@435 77 public:
duke@435 78 VMOperationQueue();
duke@435 79
duke@435 80 // Highlevel operations. Encapsulates policy
duke@435 81 bool add(VM_Operation *op);
duke@435 82 VM_Operation* remove_next(); // Returns next or null
duke@435 83 VM_Operation* remove_next_at_safepoint_priority() { return queue_remove_front(SafepointPriority); }
duke@435 84 VM_Operation* drain_at_safepoint_priority() { return queue_drain(SafepointPriority); }
duke@435 85 void set_drain_list(VM_Operation* list) { _drain_list = list; }
duke@435 86 bool peek_at_safepoint_priority() { return queue_peek(SafepointPriority); }
duke@435 87
duke@435 88 // GC support
duke@435 89 void oops_do(OopClosure* f);
duke@435 90
duke@435 91 void verify_queue(int prio) PRODUCT_RETURN;
duke@435 92 };
duke@435 93
duke@435 94
duke@435 95 //
duke@435 96 // A single VMThread (the primordial thread) spawns all other threads
duke@435 97 // and is itself used by other threads to offload heavy vm operations
duke@435 98 // like scavenge, garbage_collect etc.
duke@435 99 //
duke@435 100
minqi@1554 101 class VMThread: public NamedThread {
duke@435 102 private:
duke@435 103 static ThreadPriority _current_priority;
duke@435 104
duke@435 105 static bool _should_terminate;
duke@435 106 static bool _terminated;
duke@435 107 static Monitor * _terminate_lock;
duke@435 108 static PerfCounter* _perf_accumulated_vm_operation_time;
duke@435 109
duke@435 110 void evaluate_operation(VM_Operation* op);
duke@435 111 public:
duke@435 112 // Constructor
duke@435 113 VMThread();
duke@435 114
duke@435 115 // Tester
duke@435 116 bool is_VM_thread() const { return true; }
duke@435 117 bool is_GC_thread() const { return true; }
duke@435 118
duke@435 119 // The ever running loop for the VMThread
duke@435 120 void loop();
duke@435 121
duke@435 122 // Called to stop the VM thread
duke@435 123 static void wait_for_vm_thread_exit();
duke@435 124 static bool should_terminate() { return _should_terminate; }
duke@435 125 static bool is_terminated() { return _terminated == true; }
duke@435 126
duke@435 127 // Execution of vm operation
duke@435 128 static void execute(VM_Operation* op);
duke@435 129
duke@435 130 // Returns the current vm operation if any.
duke@435 131 static VM_Operation* vm_operation() { return _cur_vm_operation; }
duke@435 132
duke@435 133 // Returns the single instance of VMThread.
duke@435 134 static VMThread* vm_thread() { return _vm_thread; }
duke@435 135
duke@435 136 // GC support
jrose@1424 137 void oops_do(OopClosure* f, CodeBlobClosure* cf);
duke@435 138
duke@435 139 // Debugging
duke@435 140 void print_on(outputStream* st) const;
duke@435 141 void print() const { print_on(tty); }
duke@435 142 void verify();
duke@435 143
duke@435 144 // Performance measurement
duke@435 145 static PerfCounter* perf_accumulated_vm_operation_time() { return _perf_accumulated_vm_operation_time; }
duke@435 146
duke@435 147 // Entry for starting vm thread
duke@435 148 virtual void run();
duke@435 149
duke@435 150 // Creations/Destructions
duke@435 151 static void create();
duke@435 152 static void destroy();
duke@435 153
duke@435 154 private:
duke@435 155 // VM_Operation support
duke@435 156 static VM_Operation* _cur_vm_operation; // Current VM operation
duke@435 157 static VMOperationQueue* _vm_queue; // Queue (w/ policy) of VM operations
duke@435 158
duke@435 159 // Pointer to single-instance of VM thread
duke@435 160 static VMThread* _vm_thread;
duke@435 161 };
stefank@2314 162
stefank@2314 163 #endif // SHARE_VM_RUNTIME_VMTHREAD_HPP

mercurial