duke@435: /* trims@2708: * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PCTASKS_HPP stefank@2314: #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PCTASKS_HPP stefank@2314: stefank@2314: #include "gc_implementation/parallelScavenge/gcTaskManager.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psParallelCompact.hpp" stefank@2314: #include "gc_implementation/parallelScavenge/psTasks.hpp" stefank@2314: duke@435: duke@435: // Tasks for parallel compaction of the old generation duke@435: // duke@435: // Tasks are created and enqueued on a task queue. The duke@435: // tasks for parallel old collector for marking objects duke@435: // are MarkFromRootsTask and ThreadRootsMarkingTask. duke@435: // duke@435: // MarkFromRootsTask's are created duke@435: // with a root group (e.g., jni_handles) and when the do_it() duke@435: // method of a MarkFromRootsTask is executed, it starts marking duke@435: // form it's root group. duke@435: // duke@435: // ThreadRootsMarkingTask's are created for each Java thread. When duke@435: // the do_it() method of a ThreadRootsMarkingTask is executed, it duke@435: // starts marking from the thread's roots. duke@435: // duke@435: // The enqueuing of the MarkFromRootsTask and ThreadRootsMarkingTask duke@435: // do little more than create the task and put it on a queue. The duke@435: // queue is a GCTaskQueue and threads steal tasks from this GCTaskQueue. duke@435: // duke@435: // In addition to the MarkFromRootsTask and ThreadRootsMarkingTask duke@435: // tasks there are StealMarkingTask tasks. The StealMarkingTask's duke@435: // steal a reference from the marking stack of another duke@435: // thread and transitively marks the object of the reference duke@435: // and internal references. After successfully stealing a reference duke@435: // and marking it, the StealMarkingTask drains its marking stack duke@435: // stack before attempting another steal. duke@435: // duke@435: // ThreadRootsMarkingTask duke@435: // duke@435: // This task marks from the roots of a single thread. This task duke@435: // enables marking of thread roots in parallel. duke@435: // duke@435: duke@435: class ParallelTaskTerminator; duke@435: duke@435: class ThreadRootsMarkingTask : public GCTask { duke@435: private: duke@435: JavaThread* _java_thread; duke@435: VMThread* _vm_thread; duke@435: public: duke@435: ThreadRootsMarkingTask(JavaThread* root) : _java_thread(root), _vm_thread(NULL) {} duke@435: ThreadRootsMarkingTask(VMThread* root) : _java_thread(NULL), _vm_thread(root) {} duke@435: duke@435: char* name() { return (char *)"thread-roots-marking-task"; } duke@435: duke@435: virtual void do_it(GCTaskManager* manager, uint which); duke@435: }; duke@435: duke@435: duke@435: // duke@435: // MarkFromRootsTask duke@435: // duke@435: // This task marks from all the roots to all live duke@435: // objects. duke@435: // duke@435: // duke@435: duke@435: class MarkFromRootsTask : public GCTask { duke@435: public: duke@435: enum RootType { duke@435: universe = 1, duke@435: jni_handles = 2, duke@435: threads = 3, duke@435: object_synchronizer = 4, duke@435: flat_profiler = 5, duke@435: management = 6, duke@435: jvmti = 7, duke@435: system_dictionary = 8, stefank@3115: code_cache = 9 duke@435: }; duke@435: private: duke@435: RootType _root_type; duke@435: public: duke@435: MarkFromRootsTask(RootType value) : _root_type(value) {} duke@435: duke@435: char* name() { return (char *)"mark-from-roots-task"; } duke@435: duke@435: virtual void do_it(GCTaskManager* manager, uint which); duke@435: }; duke@435: duke@435: // duke@435: // RefProcTaskProxy duke@435: // duke@435: // This task is used as a proxy to parallel reference processing tasks . duke@435: // duke@435: duke@435: class RefProcTaskProxy : public GCTask { duke@435: typedef AbstractRefProcTaskExecutor::ProcessTask ProcessTask; duke@435: ProcessTask & _rp_task; duke@435: uint _work_id; duke@435: public: duke@435: RefProcTaskProxy(ProcessTask & rp_task, uint work_id) duke@435: : _rp_task(rp_task), duke@435: _work_id(work_id) duke@435: { } duke@435: duke@435: private: duke@435: virtual char* name() { return (char *)"Process referents by policy in parallel"; } duke@435: duke@435: virtual void do_it(GCTaskManager* manager, uint which); duke@435: }; duke@435: duke@435: duke@435: duke@435: // duke@435: // RefEnqueueTaskProxy duke@435: // duke@435: // This task is used as a proxy to parallel reference processing tasks . duke@435: // duke@435: duke@435: class RefEnqueueTaskProxy: public GCTask { duke@435: typedef AbstractRefProcTaskExecutor::EnqueueTask EnqueueTask; duke@435: EnqueueTask& _enq_task; duke@435: uint _work_id; duke@435: duke@435: public: duke@435: RefEnqueueTaskProxy(EnqueueTask& enq_task, uint work_id) duke@435: : _enq_task(enq_task), duke@435: _work_id(work_id) duke@435: { } duke@435: duke@435: virtual char* name() { return (char *)"Enqueue reference objects in parallel"; } duke@435: virtual void do_it(GCTaskManager* manager, uint which) duke@435: { duke@435: _enq_task.work(_work_id); duke@435: } duke@435: }; duke@435: duke@435: duke@435: // duke@435: // RefProcTaskExecutor duke@435: // duke@435: // Task executor is an interface for the reference processor to run duke@435: // tasks using GCTaskManager. duke@435: // duke@435: duke@435: class RefProcTaskExecutor: public AbstractRefProcTaskExecutor { duke@435: virtual void execute(ProcessTask& task); duke@435: virtual void execute(EnqueueTask& task); duke@435: }; duke@435: duke@435: duke@435: // duke@435: // StealMarkingTask duke@435: // duke@435: // This task is used to distribute work to idle threads. duke@435: // duke@435: duke@435: class StealMarkingTask : public GCTask { duke@435: private: duke@435: ParallelTaskTerminator* const _terminator; duke@435: private: duke@435: duke@435: public: duke@435: char* name() { return (char *)"steal-marking-task"; } duke@435: duke@435: StealMarkingTask(ParallelTaskTerminator* t); duke@435: duke@435: ParallelTaskTerminator* terminator() { return _terminator; } duke@435: duke@435: virtual void do_it(GCTaskManager* manager, uint which); duke@435: }; duke@435: duke@435: // jcoomes@810: // StealRegionCompactionTask duke@435: // duke@435: // This task is used to distribute work to idle threads. duke@435: // duke@435: jcoomes@810: class StealRegionCompactionTask : public GCTask { duke@435: private: duke@435: ParallelTaskTerminator* const _terminator; duke@435: public: jcoomes@810: StealRegionCompactionTask(ParallelTaskTerminator* t); duke@435: jcoomes@810: char* name() { return (char *)"steal-region-task"; } duke@435: ParallelTaskTerminator* terminator() { return _terminator; } duke@435: duke@435: virtual void do_it(GCTaskManager* manager, uint which); duke@435: }; duke@435: duke@435: // duke@435: // UpdateDensePrefixTask duke@435: // duke@435: // This task is used to update the dense prefix duke@435: // of a space. duke@435: // duke@435: duke@435: class UpdateDensePrefixTask : public GCTask { duke@435: private: duke@435: PSParallelCompact::SpaceId _space_id; jcoomes@810: size_t _region_index_start; jcoomes@810: size_t _region_index_end; duke@435: duke@435: public: duke@435: char* name() { return (char *)"update-dense_prefix-task"; } duke@435: duke@435: UpdateDensePrefixTask(PSParallelCompact::SpaceId space_id, jcoomes@810: size_t region_index_start, jcoomes@810: size_t region_index_end); duke@435: duke@435: virtual void do_it(GCTaskManager* manager, uint which); duke@435: }; duke@435: duke@435: // duke@435: // DrainStacksCompactionTask duke@435: // jcoomes@810: // This task processes regions that have been added to the stacks of each duke@435: // compaction manager. duke@435: // duke@435: // Trying to use one draining thread does not work because there are no duke@435: // guarantees about which task will be picked up by which thread. For example, jcoomes@810: // if thread A gets all the preloaded regions, thread A may not get a draining duke@435: // task (they may all be done by other threads). duke@435: // duke@435: duke@435: class DrainStacksCompactionTask : public GCTask { jmasa@2188: uint _stack_index; jmasa@2188: uint stack_index() { return _stack_index; } duke@435: public: jmasa@2188: DrainStacksCompactionTask(uint stack_index) : GCTask(), jmasa@2188: _stack_index(stack_index) {}; jcoomes@810: char* name() { return (char *)"drain-region-task"; } duke@435: virtual void do_it(GCTaskManager* manager, uint which); duke@435: }; stefank@2314: stefank@2314: #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PCTASKS_HPP