Tue, 08 Aug 2017 15:57:29 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2005, 2013, 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_GC_IMPLEMENTATION_PARALLELSCAVENGE_PCTASKS_HPP |
aoqi@0 | 26 | #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PCTASKS_HPP |
aoqi@0 | 27 | |
aoqi@0 | 28 | #include "gc_implementation/parallelScavenge/gcTaskManager.hpp" |
aoqi@0 | 29 | #include "gc_implementation/parallelScavenge/psParallelCompact.hpp" |
aoqi@0 | 30 | #include "gc_implementation/parallelScavenge/psTasks.hpp" |
aoqi@0 | 31 | |
aoqi@0 | 32 | |
aoqi@0 | 33 | // Tasks for parallel compaction of the old generation |
aoqi@0 | 34 | // |
aoqi@0 | 35 | // Tasks are created and enqueued on a task queue. The |
aoqi@0 | 36 | // tasks for parallel old collector for marking objects |
aoqi@0 | 37 | // are MarkFromRootsTask and ThreadRootsMarkingTask. |
aoqi@0 | 38 | // |
aoqi@0 | 39 | // MarkFromRootsTask's are created |
aoqi@0 | 40 | // with a root group (e.g., jni_handles) and when the do_it() |
aoqi@0 | 41 | // method of a MarkFromRootsTask is executed, it starts marking |
aoqi@0 | 42 | // form it's root group. |
aoqi@0 | 43 | // |
aoqi@0 | 44 | // ThreadRootsMarkingTask's are created for each Java thread. When |
aoqi@0 | 45 | // the do_it() method of a ThreadRootsMarkingTask is executed, it |
aoqi@0 | 46 | // starts marking from the thread's roots. |
aoqi@0 | 47 | // |
aoqi@0 | 48 | // The enqueuing of the MarkFromRootsTask and ThreadRootsMarkingTask |
aoqi@0 | 49 | // do little more than create the task and put it on a queue. The |
aoqi@0 | 50 | // queue is a GCTaskQueue and threads steal tasks from this GCTaskQueue. |
aoqi@0 | 51 | // |
aoqi@0 | 52 | // In addition to the MarkFromRootsTask and ThreadRootsMarkingTask |
aoqi@0 | 53 | // tasks there are StealMarkingTask tasks. The StealMarkingTask's |
aoqi@0 | 54 | // steal a reference from the marking stack of another |
aoqi@0 | 55 | // thread and transitively marks the object of the reference |
aoqi@0 | 56 | // and internal references. After successfully stealing a reference |
aoqi@0 | 57 | // and marking it, the StealMarkingTask drains its marking stack |
aoqi@0 | 58 | // stack before attempting another steal. |
aoqi@0 | 59 | // |
aoqi@0 | 60 | // ThreadRootsMarkingTask |
aoqi@0 | 61 | // |
aoqi@0 | 62 | // This task marks from the roots of a single thread. This task |
aoqi@0 | 63 | // enables marking of thread roots in parallel. |
aoqi@0 | 64 | // |
aoqi@0 | 65 | |
aoqi@0 | 66 | class ParallelTaskTerminator; |
aoqi@0 | 67 | |
aoqi@0 | 68 | class ThreadRootsMarkingTask : public GCTask { |
aoqi@0 | 69 | private: |
aoqi@0 | 70 | JavaThread* _java_thread; |
aoqi@0 | 71 | VMThread* _vm_thread; |
aoqi@0 | 72 | public: |
aoqi@0 | 73 | ThreadRootsMarkingTask(JavaThread* root) : _java_thread(root), _vm_thread(NULL) {} |
aoqi@0 | 74 | ThreadRootsMarkingTask(VMThread* root) : _java_thread(NULL), _vm_thread(root) {} |
aoqi@0 | 75 | |
aoqi@0 | 76 | char* name() { return (char *)"thread-roots-marking-task"; } |
aoqi@0 | 77 | |
aoqi@0 | 78 | virtual void do_it(GCTaskManager* manager, uint which); |
aoqi@0 | 79 | }; |
aoqi@0 | 80 | |
aoqi@0 | 81 | |
aoqi@0 | 82 | // |
aoqi@0 | 83 | // MarkFromRootsTask |
aoqi@0 | 84 | // |
aoqi@0 | 85 | // This task marks from all the roots to all live |
aoqi@0 | 86 | // objects. |
aoqi@0 | 87 | // |
aoqi@0 | 88 | // |
aoqi@0 | 89 | |
aoqi@0 | 90 | class MarkFromRootsTask : public GCTask { |
aoqi@0 | 91 | public: |
aoqi@0 | 92 | enum RootType { |
aoqi@0 | 93 | universe = 1, |
aoqi@0 | 94 | jni_handles = 2, |
aoqi@0 | 95 | threads = 3, |
aoqi@0 | 96 | object_synchronizer = 4, |
aoqi@0 | 97 | flat_profiler = 5, |
aoqi@0 | 98 | management = 6, |
aoqi@0 | 99 | jvmti = 7, |
aoqi@0 | 100 | system_dictionary = 8, |
aoqi@0 | 101 | class_loader_data = 9, |
aoqi@0 | 102 | code_cache = 10 |
aoqi@0 | 103 | }; |
aoqi@0 | 104 | private: |
aoqi@0 | 105 | RootType _root_type; |
aoqi@0 | 106 | public: |
aoqi@0 | 107 | MarkFromRootsTask(RootType value) : _root_type(value) {} |
aoqi@0 | 108 | |
aoqi@0 | 109 | char* name() { return (char *)"mark-from-roots-task"; } |
aoqi@0 | 110 | |
aoqi@0 | 111 | virtual void do_it(GCTaskManager* manager, uint which); |
aoqi@0 | 112 | }; |
aoqi@0 | 113 | |
aoqi@0 | 114 | // |
aoqi@0 | 115 | // RefProcTaskProxy |
aoqi@0 | 116 | // |
aoqi@0 | 117 | // This task is used as a proxy to parallel reference processing tasks . |
aoqi@0 | 118 | // |
aoqi@0 | 119 | |
aoqi@0 | 120 | class RefProcTaskProxy : public GCTask { |
aoqi@0 | 121 | typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask; |
aoqi@0 | 122 | ProcessTask & _rp_task; |
aoqi@0 | 123 | uint _work_id; |
aoqi@0 | 124 | public: |
aoqi@0 | 125 | RefProcTaskProxy(ProcessTask & rp_task, uint work_id) |
aoqi@0 | 126 | : _rp_task(rp_task), |
aoqi@0 | 127 | _work_id(work_id) |
aoqi@0 | 128 | { } |
aoqi@0 | 129 | |
aoqi@0 | 130 | private: |
aoqi@0 | 131 | virtual char* name() { return (char *)"Process referents by policy in parallel"; } |
aoqi@0 | 132 | |
aoqi@0 | 133 | virtual void do_it(GCTaskManager* manager, uint which); |
aoqi@0 | 134 | }; |
aoqi@0 | 135 | |
aoqi@0 | 136 | |
aoqi@0 | 137 | |
aoqi@0 | 138 | // |
aoqi@0 | 139 | // RefEnqueueTaskProxy |
aoqi@0 | 140 | // |
aoqi@0 | 141 | // This task is used as a proxy to parallel reference processing tasks . |
aoqi@0 | 142 | // |
aoqi@0 | 143 | |
aoqi@0 | 144 | class RefEnqueueTaskProxy: public GCTask { |
aoqi@0 | 145 | typedef AbstractRefProcTaskExecutor::EnqueueTask EnqueueTask; |
aoqi@0 | 146 | EnqueueTask& _enq_task; |
aoqi@0 | 147 | uint _work_id; |
aoqi@0 | 148 | |
aoqi@0 | 149 | public: |
aoqi@0 | 150 | RefEnqueueTaskProxy(EnqueueTask& enq_task, uint work_id) |
aoqi@0 | 151 | : _enq_task(enq_task), |
aoqi@0 | 152 | _work_id(work_id) |
aoqi@0 | 153 | { } |
aoqi@0 | 154 | |
aoqi@0 | 155 | virtual char* name() { return (char *)"Enqueue reference objects in parallel"; } |
aoqi@0 | 156 | virtual void do_it(GCTaskManager* manager, uint which) |
aoqi@0 | 157 | { |
aoqi@0 | 158 | _enq_task.work(_work_id); |
aoqi@0 | 159 | } |
aoqi@0 | 160 | }; |
aoqi@0 | 161 | |
aoqi@0 | 162 | |
aoqi@0 | 163 | // |
aoqi@0 | 164 | // RefProcTaskExecutor |
aoqi@0 | 165 | // |
aoqi@0 | 166 | // Task executor is an interface for the reference processor to run |
aoqi@0 | 167 | // tasks using GCTaskManager. |
aoqi@0 | 168 | // |
aoqi@0 | 169 | |
aoqi@0 | 170 | class RefProcTaskExecutor: public AbstractRefProcTaskExecutor { |
aoqi@0 | 171 | virtual void execute(ProcessTask& task); |
aoqi@0 | 172 | virtual void execute(EnqueueTask& task); |
aoqi@0 | 173 | }; |
aoqi@0 | 174 | |
aoqi@0 | 175 | |
aoqi@0 | 176 | // |
aoqi@0 | 177 | // StealMarkingTask |
aoqi@0 | 178 | // |
aoqi@0 | 179 | // This task is used to distribute work to idle threads. |
aoqi@0 | 180 | // |
aoqi@0 | 181 | |
aoqi@0 | 182 | class StealMarkingTask : public GCTask { |
aoqi@0 | 183 | private: |
aoqi@0 | 184 | ParallelTaskTerminator* const _terminator; |
aoqi@0 | 185 | private: |
aoqi@0 | 186 | |
aoqi@0 | 187 | public: |
aoqi@0 | 188 | char* name() { return (char *)"steal-marking-task"; } |
aoqi@0 | 189 | |
aoqi@0 | 190 | StealMarkingTask(ParallelTaskTerminator* t); |
aoqi@0 | 191 | |
aoqi@0 | 192 | ParallelTaskTerminator* terminator() { return _terminator; } |
aoqi@0 | 193 | |
aoqi@0 | 194 | virtual void do_it(GCTaskManager* manager, uint which); |
aoqi@0 | 195 | }; |
aoqi@0 | 196 | |
aoqi@0 | 197 | // |
aoqi@0 | 198 | // StealRegionCompactionTask |
aoqi@0 | 199 | // |
aoqi@0 | 200 | // This task is used to distribute work to idle threads. |
aoqi@0 | 201 | // |
aoqi@0 | 202 | |
aoqi@0 | 203 | class StealRegionCompactionTask : public GCTask { |
aoqi@0 | 204 | private: |
aoqi@0 | 205 | ParallelTaskTerminator* const _terminator; |
aoqi@0 | 206 | public: |
aoqi@0 | 207 | StealRegionCompactionTask(ParallelTaskTerminator* t); |
aoqi@0 | 208 | |
aoqi@0 | 209 | char* name() { return (char *)"steal-region-task"; } |
aoqi@0 | 210 | ParallelTaskTerminator* terminator() { return _terminator; } |
aoqi@0 | 211 | |
aoqi@0 | 212 | virtual void do_it(GCTaskManager* manager, uint which); |
aoqi@0 | 213 | }; |
aoqi@0 | 214 | |
aoqi@0 | 215 | // |
aoqi@0 | 216 | // UpdateDensePrefixTask |
aoqi@0 | 217 | // |
aoqi@0 | 218 | // This task is used to update the dense prefix |
aoqi@0 | 219 | // of a space. |
aoqi@0 | 220 | // |
aoqi@0 | 221 | |
aoqi@0 | 222 | class UpdateDensePrefixTask : public GCTask { |
aoqi@0 | 223 | private: |
aoqi@0 | 224 | PSParallelCompact::SpaceId _space_id; |
aoqi@0 | 225 | size_t _region_index_start; |
aoqi@0 | 226 | size_t _region_index_end; |
aoqi@0 | 227 | |
aoqi@0 | 228 | public: |
aoqi@0 | 229 | char* name() { return (char *)"update-dense_prefix-task"; } |
aoqi@0 | 230 | |
aoqi@0 | 231 | UpdateDensePrefixTask(PSParallelCompact::SpaceId space_id, |
aoqi@0 | 232 | size_t region_index_start, |
aoqi@0 | 233 | size_t region_index_end); |
aoqi@0 | 234 | |
aoqi@0 | 235 | virtual void do_it(GCTaskManager* manager, uint which); |
aoqi@0 | 236 | }; |
aoqi@0 | 237 | |
aoqi@0 | 238 | // |
aoqi@0 | 239 | // DrainStacksCompactionTask |
aoqi@0 | 240 | // |
aoqi@0 | 241 | // This task processes regions that have been added to the stacks of each |
aoqi@0 | 242 | // compaction manager. |
aoqi@0 | 243 | // |
aoqi@0 | 244 | // Trying to use one draining thread does not work because there are no |
aoqi@0 | 245 | // guarantees about which task will be picked up by which thread. For example, |
aoqi@0 | 246 | // if thread A gets all the preloaded regions, thread A may not get a draining |
aoqi@0 | 247 | // task (they may all be done by other threads). |
aoqi@0 | 248 | // |
aoqi@0 | 249 | |
aoqi@0 | 250 | class DrainStacksCompactionTask : public GCTask { |
aoqi@0 | 251 | uint _stack_index; |
aoqi@0 | 252 | uint stack_index() { return _stack_index; } |
aoqi@0 | 253 | public: |
aoqi@0 | 254 | DrainStacksCompactionTask(uint stack_index) : GCTask(), |
aoqi@0 | 255 | _stack_index(stack_index) {}; |
aoqi@0 | 256 | char* name() { return (char *)"drain-region-task"; } |
aoqi@0 | 257 | virtual void do_it(GCTaskManager* manager, uint which); |
aoqi@0 | 258 | }; |
aoqi@0 | 259 | |
aoqi@0 | 260 | #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PCTASKS_HPP |