src/share/vm/runtime/vmThread.hpp

Tue, 11 May 2010 14:35:43 -0700

author
prr
date
Tue, 11 May 2010 14:35:43 -0700
changeset 1840
fb57d4cf76c2
parent 1554
547f81740344
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6931180: Migration to recent versions of MS Platform SDK
6951582: Build problems on win64
Summary: Changes to enable building JDK7 with Microsoft Visual Studio 2010
Reviewed-by: ohair, art, ccheung, dcubed

duke@435 1 /*
duke@435 2 * Copyright 1998-2006 Sun Microsystems, Inc. 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 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 //
duke@435 26 // Prioritized queue of VM operations.
duke@435 27 //
duke@435 28 // Encapsulates both queue management and
duke@435 29 // and priority policy
duke@435 30 //
duke@435 31 class VMOperationQueue : public CHeapObj {
duke@435 32 private:
duke@435 33 enum Priorities {
duke@435 34 SafepointPriority, // Highest priority (operation executed at a safepoint)
duke@435 35 MediumPriority, // Medium priority
duke@435 36 nof_priorities
duke@435 37 };
duke@435 38
duke@435 39 // We maintain a doubled linked list, with explicit count.
duke@435 40 int _queue_length[nof_priorities];
duke@435 41 int _queue_counter;
duke@435 42 VM_Operation* _queue [nof_priorities];
duke@435 43 // we also allow the vmThread to register the ops it has drained so we
duke@435 44 // can scan them from oops_do
duke@435 45 VM_Operation* _drain_list;
duke@435 46
duke@435 47 // Double-linked non-empty list insert.
duke@435 48 void insert(VM_Operation* q,VM_Operation* n);
duke@435 49 void unlink(VM_Operation* q);
duke@435 50
duke@435 51 // Basic queue manipulation
duke@435 52 bool queue_empty (int prio);
duke@435 53 void queue_add_front (int prio, VM_Operation *op);
duke@435 54 void queue_add_back (int prio, VM_Operation *op);
duke@435 55 VM_Operation* queue_remove_front(int prio);
duke@435 56 void queue_oops_do(int queue, OopClosure* f);
duke@435 57 void drain_list_oops_do(OopClosure* f);
duke@435 58 VM_Operation* queue_drain(int prio);
duke@435 59 // lock-free query: may return the wrong answer but must not break
duke@435 60 bool queue_peek(int prio) { return _queue_length[prio] > 0; }
duke@435 61
duke@435 62 public:
duke@435 63 VMOperationQueue();
duke@435 64
duke@435 65 // Highlevel operations. Encapsulates policy
duke@435 66 bool add(VM_Operation *op);
duke@435 67 VM_Operation* remove_next(); // Returns next or null
duke@435 68 VM_Operation* remove_next_at_safepoint_priority() { return queue_remove_front(SafepointPriority); }
duke@435 69 VM_Operation* drain_at_safepoint_priority() { return queue_drain(SafepointPriority); }
duke@435 70 void set_drain_list(VM_Operation* list) { _drain_list = list; }
duke@435 71 bool peek_at_safepoint_priority() { return queue_peek(SafepointPriority); }
duke@435 72
duke@435 73 // GC support
duke@435 74 void oops_do(OopClosure* f);
duke@435 75
duke@435 76 void verify_queue(int prio) PRODUCT_RETURN;
duke@435 77 };
duke@435 78
duke@435 79
duke@435 80 //
duke@435 81 // A single VMThread (the primordial thread) spawns all other threads
duke@435 82 // and is itself used by other threads to offload heavy vm operations
duke@435 83 // like scavenge, garbage_collect etc.
duke@435 84 //
duke@435 85
minqi@1554 86 class VMThread: public NamedThread {
duke@435 87 private:
duke@435 88 static ThreadPriority _current_priority;
duke@435 89
duke@435 90 static bool _should_terminate;
duke@435 91 static bool _terminated;
duke@435 92 static Monitor * _terminate_lock;
duke@435 93 static PerfCounter* _perf_accumulated_vm_operation_time;
duke@435 94
duke@435 95 void evaluate_operation(VM_Operation* op);
duke@435 96 public:
duke@435 97 // Constructor
duke@435 98 VMThread();
duke@435 99
duke@435 100 // Tester
duke@435 101 bool is_VM_thread() const { return true; }
duke@435 102 bool is_GC_thread() const { return true; }
duke@435 103
duke@435 104 // The ever running loop for the VMThread
duke@435 105 void loop();
duke@435 106
duke@435 107 // Called to stop the VM thread
duke@435 108 static void wait_for_vm_thread_exit();
duke@435 109 static bool should_terminate() { return _should_terminate; }
duke@435 110 static bool is_terminated() { return _terminated == true; }
duke@435 111
duke@435 112 // Execution of vm operation
duke@435 113 static void execute(VM_Operation* op);
duke@435 114
duke@435 115 // Returns the current vm operation if any.
duke@435 116 static VM_Operation* vm_operation() { return _cur_vm_operation; }
duke@435 117
duke@435 118 // Returns the single instance of VMThread.
duke@435 119 static VMThread* vm_thread() { return _vm_thread; }
duke@435 120
duke@435 121 // GC support
jrose@1424 122 void oops_do(OopClosure* f, CodeBlobClosure* cf);
duke@435 123
duke@435 124 // Debugging
duke@435 125 void print_on(outputStream* st) const;
duke@435 126 void print() const { print_on(tty); }
duke@435 127 void verify();
duke@435 128
duke@435 129 // Performance measurement
duke@435 130 static PerfCounter* perf_accumulated_vm_operation_time() { return _perf_accumulated_vm_operation_time; }
duke@435 131
duke@435 132 // Entry for starting vm thread
duke@435 133 virtual void run();
duke@435 134
duke@435 135 // Creations/Destructions
duke@435 136 static void create();
duke@435 137 static void destroy();
duke@435 138
duke@435 139 private:
duke@435 140 // VM_Operation support
duke@435 141 static VM_Operation* _cur_vm_operation; // Current VM operation
duke@435 142 static VMOperationQueue* _vm_queue; // Queue (w/ policy) of VM operations
duke@435 143
duke@435 144 // Pointer to single-instance of VM thread
duke@435 145 static VMThread* _vm_thread;
duke@435 146 };

mercurial