src/share/vm/runtime/vmThread.hpp

Sun, 25 Sep 2011 16:03:29 -0700

author
never
date
Sun, 25 Sep 2011 16:03:29 -0700
changeset 3156
f08d439fab8c
parent 2314
f95d63e2154a
child 3900
d2a62e0f25eb
permissions
-rw-r--r--

7089790: integrate bsd-port changes
Reviewed-by: kvn, twisti, jrose
Contributed-by: Kurt Miller <kurt@intricatesoftware.com>, Greg Lewis <glewis@eyesbeyond.com>, Jung-uk Kim <jkim@freebsd.org>, Christos Zoulas <christos@zoulas.com>, Landon Fuller <landonf@plausible.coop>, The FreeBSD Foundation <board@freebsdfoundation.org>, Michael Franz <mvfranz@gmail.com>, Roger Hoover <rhoover@apple.com>, Alexander Strange <astrange@apple.com>

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
never@3156 39 #ifdef TARGET_OS_FAMILY_bsd
never@3156 40 # include "thread_bsd.inline.hpp"
never@3156 41 #endif
stefank@2314 42
duke@435 43 //
duke@435 44 // Prioritized queue of VM operations.
duke@435 45 //
duke@435 46 // Encapsulates both queue management and
duke@435 47 // and priority policy
duke@435 48 //
duke@435 49 class VMOperationQueue : public CHeapObj {
duke@435 50 private:
duke@435 51 enum Priorities {
duke@435 52 SafepointPriority, // Highest priority (operation executed at a safepoint)
duke@435 53 MediumPriority, // Medium priority
duke@435 54 nof_priorities
duke@435 55 };
duke@435 56
duke@435 57 // We maintain a doubled linked list, with explicit count.
duke@435 58 int _queue_length[nof_priorities];
duke@435 59 int _queue_counter;
duke@435 60 VM_Operation* _queue [nof_priorities];
duke@435 61 // we also allow the vmThread to register the ops it has drained so we
duke@435 62 // can scan them from oops_do
duke@435 63 VM_Operation* _drain_list;
duke@435 64
duke@435 65 // Double-linked non-empty list insert.
duke@435 66 void insert(VM_Operation* q,VM_Operation* n);
duke@435 67 void unlink(VM_Operation* q);
duke@435 68
duke@435 69 // Basic queue manipulation
duke@435 70 bool queue_empty (int prio);
duke@435 71 void queue_add_front (int prio, VM_Operation *op);
duke@435 72 void queue_add_back (int prio, VM_Operation *op);
duke@435 73 VM_Operation* queue_remove_front(int prio);
duke@435 74 void queue_oops_do(int queue, OopClosure* f);
duke@435 75 void drain_list_oops_do(OopClosure* f);
duke@435 76 VM_Operation* queue_drain(int prio);
duke@435 77 // lock-free query: may return the wrong answer but must not break
duke@435 78 bool queue_peek(int prio) { return _queue_length[prio] > 0; }
duke@435 79
duke@435 80 public:
duke@435 81 VMOperationQueue();
duke@435 82
duke@435 83 // Highlevel operations. Encapsulates policy
duke@435 84 bool add(VM_Operation *op);
duke@435 85 VM_Operation* remove_next(); // Returns next or null
duke@435 86 VM_Operation* remove_next_at_safepoint_priority() { return queue_remove_front(SafepointPriority); }
duke@435 87 VM_Operation* drain_at_safepoint_priority() { return queue_drain(SafepointPriority); }
duke@435 88 void set_drain_list(VM_Operation* list) { _drain_list = list; }
duke@435 89 bool peek_at_safepoint_priority() { return queue_peek(SafepointPriority); }
duke@435 90
duke@435 91 // GC support
duke@435 92 void oops_do(OopClosure* f);
duke@435 93
duke@435 94 void verify_queue(int prio) PRODUCT_RETURN;
duke@435 95 };
duke@435 96
duke@435 97
duke@435 98 //
duke@435 99 // A single VMThread (the primordial thread) spawns all other threads
duke@435 100 // and is itself used by other threads to offload heavy vm operations
duke@435 101 // like scavenge, garbage_collect etc.
duke@435 102 //
duke@435 103
minqi@1554 104 class VMThread: public NamedThread {
duke@435 105 private:
duke@435 106 static ThreadPriority _current_priority;
duke@435 107
duke@435 108 static bool _should_terminate;
duke@435 109 static bool _terminated;
duke@435 110 static Monitor * _terminate_lock;
duke@435 111 static PerfCounter* _perf_accumulated_vm_operation_time;
duke@435 112
duke@435 113 void evaluate_operation(VM_Operation* op);
duke@435 114 public:
duke@435 115 // Constructor
duke@435 116 VMThread();
duke@435 117
duke@435 118 // Tester
duke@435 119 bool is_VM_thread() const { return true; }
duke@435 120 bool is_GC_thread() const { return true; }
duke@435 121
duke@435 122 // The ever running loop for the VMThread
duke@435 123 void loop();
duke@435 124
duke@435 125 // Called to stop the VM thread
duke@435 126 static void wait_for_vm_thread_exit();
duke@435 127 static bool should_terminate() { return _should_terminate; }
duke@435 128 static bool is_terminated() { return _terminated == true; }
duke@435 129
duke@435 130 // Execution of vm operation
duke@435 131 static void execute(VM_Operation* op);
duke@435 132
duke@435 133 // Returns the current vm operation if any.
duke@435 134 static VM_Operation* vm_operation() { return _cur_vm_operation; }
duke@435 135
duke@435 136 // Returns the single instance of VMThread.
duke@435 137 static VMThread* vm_thread() { return _vm_thread; }
duke@435 138
duke@435 139 // GC support
jrose@1424 140 void oops_do(OopClosure* f, CodeBlobClosure* cf);
duke@435 141
duke@435 142 // Debugging
duke@435 143 void print_on(outputStream* st) const;
duke@435 144 void print() const { print_on(tty); }
duke@435 145 void verify();
duke@435 146
duke@435 147 // Performance measurement
duke@435 148 static PerfCounter* perf_accumulated_vm_operation_time() { return _perf_accumulated_vm_operation_time; }
duke@435 149
duke@435 150 // Entry for starting vm thread
duke@435 151 virtual void run();
duke@435 152
duke@435 153 // Creations/Destructions
duke@435 154 static void create();
duke@435 155 static void destroy();
duke@435 156
duke@435 157 private:
duke@435 158 // VM_Operation support
duke@435 159 static VM_Operation* _cur_vm_operation; // Current VM operation
duke@435 160 static VMOperationQueue* _vm_queue; // Queue (w/ policy) of VM operations
duke@435 161
duke@435 162 // Pointer to single-instance of VM thread
duke@435 163 static VMThread* _vm_thread;
duke@435 164 };
stefank@2314 165
stefank@2314 166 #endif // SHARE_VM_RUNTIME_VMTHREAD_HPP

mercurial