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