src/share/vm/runtime/vmThread.hpp

Wed, 03 Jul 2019 20:42:37 +0800

author
aoqi
date
Wed, 03 Jul 2019 20:42:37 +0800
changeset 9637
eef07cd490d4
parent 7535
7ae4e26cb1e0
child 9931
fd44df5e3bc3
permissions
-rw-r--r--

Merge

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

mercurial