| 1 | /* | 
|---|
| 2 | * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. | 
|---|
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 
|---|
| 4 | * | 
|---|
| 5 | * This code is free software; you can redistribute it and/or modify it | 
|---|
| 6 | * under the terms of the GNU General Public License version 2 only, as | 
|---|
| 7 | * published by the Free Software Foundation. | 
|---|
| 8 | * | 
|---|
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT | 
|---|
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | 
|---|
| 11 | * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License | 
|---|
| 12 | * version 2 for more details (a copy is included in the LICENSE file that | 
|---|
| 13 | * accompanied this code). | 
|---|
| 14 | * | 
|---|
| 15 | * You should have received a copy of the GNU General Public License version | 
|---|
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, | 
|---|
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | 
|---|
| 18 | * | 
|---|
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | 
|---|
| 20 | * or visit www.oracle.com if you need additional information or have any | 
|---|
| 21 | * questions. | 
|---|
| 22 | * | 
|---|
| 23 | */ | 
|---|
| 24 |  | 
|---|
| 25 | #ifndef SHARE_GC_SHARED_WEAKPROCESSOR_HPP | 
|---|
| 26 | #define SHARE_GC_SHARED_WEAKPROCESSOR_HPP | 
|---|
| 27 |  | 
|---|
| 28 | #include "gc/shared/oopStorageParState.hpp" | 
|---|
| 29 | #include "gc/shared/workgroup.hpp" | 
|---|
| 30 | #include "memory/allocation.hpp" | 
|---|
| 31 |  | 
|---|
| 32 | class WeakProcessorPhaseTimes; | 
|---|
| 33 | class WorkGang; | 
|---|
| 34 |  | 
|---|
| 35 | // Helper class to aid in root scanning and cleaning of weak oops in the VM. | 
|---|
| 36 | // | 
|---|
| 37 | // New containers of weak oops added to this class will automatically | 
|---|
| 38 | // be cleaned by all GCs, including the young generation GCs. | 
|---|
| 39 | class WeakProcessor : AllStatic { | 
|---|
| 40 | public: | 
|---|
| 41 | // Visit all oop*s and apply the keep_alive closure if the referenced | 
|---|
| 42 | // object is considered alive by the is_alive closure, otherwise do some | 
|---|
| 43 | // container specific cleanup of element holding the oop. | 
|---|
| 44 | static void weak_oops_do(BoolObjectClosure* is_alive, OopClosure* keep_alive); | 
|---|
| 45 |  | 
|---|
| 46 | // Visit all oop*s and apply the given closure. | 
|---|
| 47 | static void oops_do(OopClosure* closure); | 
|---|
| 48 |  | 
|---|
| 49 | // Parallel version.  Uses ergo_workers(), active workers, and | 
|---|
| 50 | // phase_time's max_threads to determine the number of threads to use. | 
|---|
| 51 | // IsAlive must be derived from BoolObjectClosure. | 
|---|
| 52 | // KeepAlive must be derived from OopClosure. | 
|---|
| 53 | template<typename IsAlive, typename KeepAlive> | 
|---|
| 54 | static void weak_oops_do(WorkGang* workers, | 
|---|
| 55 | IsAlive* is_alive, | 
|---|
| 56 | KeepAlive* keep_alive, | 
|---|
| 57 | WeakProcessorPhaseTimes* phase_times); | 
|---|
| 58 |  | 
|---|
| 59 | // Convenience parallel version.  Uses ergo_workers() and active workers | 
|---|
| 60 | // to determine the number of threads to run.  Implicitly logs phase times. | 
|---|
| 61 | // IsAlive must be derived from BoolObjectClosure. | 
|---|
| 62 | // KeepAlive must be derived from OopClosure. | 
|---|
| 63 | template<typename IsAlive, typename KeepAlive> | 
|---|
| 64 | static void weak_oops_do(WorkGang* workers, | 
|---|
| 65 | IsAlive* is_alive, | 
|---|
| 66 | KeepAlive* keep_alive, | 
|---|
| 67 | uint indent_log); | 
|---|
| 68 |  | 
|---|
| 69 | static uint ergo_workers(uint max_workers); | 
|---|
| 70 | class Task; | 
|---|
| 71 |  | 
|---|
| 72 | private: | 
|---|
| 73 | class GangTask; | 
|---|
| 74 | }; | 
|---|
| 75 |  | 
|---|
| 76 | class WeakProcessor::Task { | 
|---|
| 77 | typedef OopStorage::ParState<false, false> StorageState; | 
|---|
| 78 |  | 
|---|
| 79 | WeakProcessorPhaseTimes* _phase_times; | 
|---|
| 80 | uint _nworkers; | 
|---|
| 81 | SubTasksDone _serial_phases_done; | 
|---|
| 82 | StorageState* _storage_states; | 
|---|
| 83 |  | 
|---|
| 84 | void initialize(); | 
|---|
| 85 |  | 
|---|
| 86 | public: | 
|---|
| 87 | Task(uint nworkers);          // No time tracking. | 
|---|
| 88 | Task(WeakProcessorPhaseTimes* phase_times, uint nworkers); | 
|---|
| 89 | ~Task(); | 
|---|
| 90 |  | 
|---|
| 91 | template<typename IsAlive, typename KeepAlive> | 
|---|
| 92 | void work(uint worker_id, IsAlive* is_alive, KeepAlive* keep_alive); | 
|---|
| 93 | }; | 
|---|
| 94 |  | 
|---|
| 95 | #endif // SHARE_GC_SHARED_WEAKPROCESSOR_HPP | 
|---|
| 96 |  | 
|---|