| 1 | /* |
| 2 | * Copyright (c) 2000, 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_CARDTABLEBARRIERSET_HPP |
| 26 | #define SHARE_GC_SHARED_CARDTABLEBARRIERSET_HPP |
| 27 | |
| 28 | #include "gc/shared/cardTable.hpp" |
| 29 | #include "gc/shared/modRefBarrierSet.hpp" |
| 30 | #include "utilities/align.hpp" |
| 31 | |
| 32 | // This kind of "BarrierSet" allows a "CollectedHeap" to detect and |
| 33 | // enumerate ref fields that have been modified (since the last |
| 34 | // enumeration.) |
| 35 | |
| 36 | // As it currently stands, this barrier is *imprecise*: when a ref field in |
| 37 | // an object "o" is modified, the card table entry for the card containing |
| 38 | // the head of "o" is dirtied, not necessarily the card containing the |
| 39 | // modified field itself. For object arrays, however, the barrier *is* |
| 40 | // precise; only the card containing the modified element is dirtied. |
| 41 | // Closures used to scan dirty cards should take these |
| 42 | // considerations into account. |
| 43 | |
| 44 | class CardTableBarrierSet: public ModRefBarrierSet { |
| 45 | // Some classes get to look at some private stuff. |
| 46 | friend class VMStructs; |
| 47 | |
| 48 | public: |
| 49 | |
| 50 | typedef CardTable::CardValue CardValue; |
| 51 | protected: |
| 52 | // Used in support of ReduceInitialCardMarks; only consulted if COMPILER2 |
| 53 | // or INCLUDE_JVMCI is being used |
| 54 | bool _defer_initial_card_mark; |
| 55 | CardTable* _card_table; |
| 56 | |
| 57 | CardTableBarrierSet(BarrierSetAssembler* barrier_set_assembler, |
| 58 | BarrierSetC1* barrier_set_c1, |
| 59 | BarrierSetC2* barrier_set_c2, |
| 60 | CardTable* card_table, |
| 61 | const BarrierSet::FakeRtti& fake_rtti); |
| 62 | |
| 63 | public: |
| 64 | CardTableBarrierSet(CardTable* card_table); |
| 65 | ~CardTableBarrierSet(); |
| 66 | |
| 67 | CardTable* card_table() const { return _card_table; } |
| 68 | |
| 69 | virtual void initialize(); |
| 70 | |
| 71 | void write_region(MemRegion mr) { |
| 72 | invalidate(mr); |
| 73 | } |
| 74 | |
| 75 | void write_ref_array_work(MemRegion mr); |
| 76 | |
| 77 | public: |
| 78 | // Record a reference update. Note that these versions are precise! |
| 79 | // The scanning code has to handle the fact that the write barrier may be |
| 80 | // either precise or imprecise. We make non-virtual inline variants of |
| 81 | // these functions here for performance. |
| 82 | template <DecoratorSet decorators, typename T> |
| 83 | void write_ref_field_post(T* field, oop newVal); |
| 84 | |
| 85 | virtual void invalidate(MemRegion mr); |
| 86 | |
| 87 | // ReduceInitialCardMarks |
| 88 | void initialize_deferred_card_mark_barriers(); |
| 89 | |
| 90 | // If the CollectedHeap was asked to defer a store barrier above, |
| 91 | // this informs it to flush such a deferred store barrier to the |
| 92 | // remembered set. |
| 93 | void flush_deferred_card_mark_barrier(JavaThread* thread); |
| 94 | |
| 95 | // If a compiler is eliding store barriers for TLAB-allocated objects, |
| 96 | // we will be informed of a slow-path allocation by a call |
| 97 | // to on_slowpath_allocation_exit() below. Such a call precedes the |
| 98 | // initialization of the object itself, and no post-store-barriers will |
| 99 | // be issued. Some heap types require that the barrier strictly follows |
| 100 | // the initializing stores. (This is currently implemented by deferring the |
| 101 | // barrier until the next slow-path allocation or gc-related safepoint.) |
| 102 | // This interface answers whether a particular barrier type needs the card |
| 103 | // mark to be thus strictly sequenced after the stores. |
| 104 | virtual bool card_mark_must_follow_store() const; |
| 105 | |
| 106 | virtual void on_slowpath_allocation_exit(JavaThread* thread, oop new_obj); |
| 107 | virtual void on_thread_detach(Thread* thread); |
| 108 | |
| 109 | virtual void make_parsable(JavaThread* thread) { flush_deferred_card_mark_barrier(thread); } |
| 110 | |
| 111 | virtual void print_on(outputStream* st) const; |
| 112 | |
| 113 | template <DecoratorSet decorators, typename BarrierSetT = CardTableBarrierSet> |
| 114 | class AccessBarrier: public ModRefBarrierSet::AccessBarrier<decorators, BarrierSetT> {}; |
| 115 | }; |
| 116 | |
| 117 | template<> |
| 118 | struct BarrierSet::GetName<CardTableBarrierSet> { |
| 119 | static const BarrierSet::Name value = BarrierSet::CardTableBarrierSet; |
| 120 | }; |
| 121 | |
| 122 | template<> |
| 123 | struct BarrierSet::GetType<BarrierSet::CardTableBarrierSet> { |
| 124 | typedef ::CardTableBarrierSet type; |
| 125 | }; |
| 126 | |
| 127 | #endif // SHARE_GC_SHARED_CARDTABLEBARRIERSET_HPP |
| 128 | |