| 1 | /* |
| 2 | * Copyright (c) 2018, 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_OOPSTORAGEPARSTATE_INLINE_HPP |
| 26 | #define SHARE_GC_SHARED_OOPSTORAGEPARSTATE_INLINE_HPP |
| 27 | |
| 28 | #include "gc/shared/oopStorage.inline.hpp" |
| 29 | #include "gc/shared/oopStorageParState.hpp" |
| 30 | #include "metaprogramming/conditional.hpp" |
| 31 | #include "utilities/macros.hpp" |
| 32 | |
| 33 | template<typename F> |
| 34 | class OopStorage::BasicParState::AlwaysTrueFn { |
| 35 | F _f; |
| 36 | |
| 37 | public: |
| 38 | AlwaysTrueFn(F f) : _f(f) {} |
| 39 | |
| 40 | template<typename OopPtr> // [const] oop* |
| 41 | bool operator()(OopPtr ptr) const { _f(ptr); return true; } |
| 42 | }; |
| 43 | |
| 44 | struct OopStorage::BasicParState::IterationData { |
| 45 | size_t _segment_start; |
| 46 | size_t _segment_end; |
| 47 | size_t _processed; |
| 48 | }; |
| 49 | |
| 50 | template<bool is_const, typename F> |
| 51 | inline void OopStorage::BasicParState::iterate(F f) { |
| 52 | // Wrap f in ATF so we can use Block::iterate. |
| 53 | AlwaysTrueFn<F> atf_f(f); |
| 54 | IterationData data = {}; // zero initialize. |
| 55 | while (claim_next_segment(&data)) { |
| 56 | assert(data._segment_start < data._segment_end, "invariant" ); |
| 57 | assert(data._segment_end <= _block_count, "invariant" ); |
| 58 | typedef typename Conditional<is_const, const Block*, Block*>::type BlockPtr; |
| 59 | size_t i = data._segment_start; |
| 60 | do { |
| 61 | BlockPtr block = _active_array->at(i); |
| 62 | block->iterate(atf_f); |
| 63 | } while (++i < data._segment_end); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | template<bool concurrent, bool is_const> |
| 68 | template<typename F> |
| 69 | inline void OopStorage::ParState<concurrent, is_const>::iterate(F f) { |
| 70 | _basic_state.template iterate<is_const>(f); |
| 71 | } |
| 72 | |
| 73 | template<bool concurrent, bool is_const> |
| 74 | template<typename Closure> |
| 75 | inline void OopStorage::ParState<concurrent, is_const>::oops_do(Closure* cl) { |
| 76 | this->iterate(oop_fn(cl)); |
| 77 | } |
| 78 | |
| 79 | template<typename F> |
| 80 | inline void OopStorage::ParState<false, false>::iterate(F f) { |
| 81 | _basic_state.template iterate<false>(f); |
| 82 | } |
| 83 | |
| 84 | template<typename Closure> |
| 85 | inline void OopStorage::ParState<false, false>::oops_do(Closure* cl) { |
| 86 | this->iterate(oop_fn(cl)); |
| 87 | } |
| 88 | |
| 89 | template<typename Closure> |
| 90 | inline void OopStorage::ParState<false, false>::weak_oops_do(Closure* cl) { |
| 91 | this->iterate(skip_null_fn(oop_fn(cl))); |
| 92 | } |
| 93 | |
| 94 | template<typename IsAliveClosure, typename Closure> |
| 95 | inline void OopStorage::ParState<false, false>::weak_oops_do(IsAliveClosure* is_alive, Closure* cl) { |
| 96 | this->iterate(if_alive_fn(is_alive, oop_fn(cl))); |
| 97 | } |
| 98 | |
| 99 | #endif // SHARE_GC_SHARED_OOPSTORAGEPARSTATE_INLINE_HPP |
| 100 | |