Mercurial > hg > graal-jvmci-8
annotate src/share/vm/gc_implementation/g1/g1ParScanThreadState.hpp @ 22901:c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
Summary: Evaluate and improve object copy time by micro-optimizations and splitting out slow and fast paths aggressively.
Reviewed-by: kbarrett, mgerdin, jmasa
Contributed-by: Tony Printezis <tprintezis@twitter.com>, Thomas Schatzl <thomas.schatzl@oracle.com>
author | tschatzl |
---|---|
date | Fri, 19 Dec 2014 09:21:06 +0100 |
parents | f2e3f0e1f97d |
children |
rev | line source |
---|---|
20223 | 1 /* |
2 * Copyright (c) 2014, 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_IMPLEMENTATION_G1_G1PARSCANTHREADSTATE_HPP | |
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_G1PARSCANTHREADSTATE_HPP | |
27 | |
28 #include "gc_implementation/g1/dirtyCardQueue.hpp" | |
29 #include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" | |
30 #include "gc_implementation/g1/g1CollectedHeap.hpp" | |
31 #include "gc_implementation/g1/g1CollectorPolicy.hpp" | |
32 #include "gc_implementation/g1/g1OopClosures.hpp" | |
33 #include "gc_implementation/g1/g1RemSet.hpp" | |
34 #include "gc_implementation/shared/ageTable.hpp" | |
35 #include "memory/allocation.hpp" | |
36 #include "oops/oop.hpp" | |
37 | |
38 class HeapRegion; | |
39 class outputStream; | |
40 | |
41 class G1ParScanThreadState : public StackObj { | |
20224
a2328cbebb23
8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents:
20223
diff
changeset
|
42 private: |
20223 | 43 G1CollectedHeap* _g1h; |
44 RefToScanQueue* _refs; | |
45 DirtyCardQueue _dcq; | |
46 G1SATBCardTableModRefBS* _ct_bs; | |
47 G1RemSet* _g1_rem; | |
48 | |
22901
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
49 G1ParGCAllocator* _g1_par_allocator; |
20223 | 50 |
22901
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
51 ageTable _age_table; |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
52 InCSetState _dest[InCSetState::Num]; |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
53 // Local tenuring threshold. |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
54 uint _tenuring_threshold; |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
55 G1ParScanClosure _scanner; |
20223 | 56 |
22901
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
57 size_t _alloc_buffer_waste; |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
58 size_t _undo_waste; |
20223 | 59 |
60 OopsInHeapRegionClosure* _evac_failure_cl; | |
61 | |
62 int _hash_seed; | |
63 uint _queue_num; | |
64 | |
65 size_t _term_attempts; | |
66 | |
67 double _start; | |
68 double _start_strong_roots; | |
69 double _strong_roots_time; | |
70 double _start_term; | |
71 double _term_time; | |
72 | |
73 // Map from young-age-index (0 == not young, 1 is youngest) to | |
74 // surviving words. base is what we get back from the malloc call | |
75 size_t* _surviving_young_words_base; | |
76 // this points into the array, as we use the first few entries for padding | |
77 size_t* _surviving_young_words; | |
78 | |
79 #define PADDING_ELEM_NUM (DEFAULT_CACHE_LINE_SIZE / sizeof(size_t)) | |
80 | |
81 void add_to_alloc_buffer_waste(size_t waste) { _alloc_buffer_waste += waste; } | |
82 void add_to_undo_waste(size_t waste) { _undo_waste += waste; } | |
83 | |
84 DirtyCardQueue& dirty_card_queue() { return _dcq; } | |
85 G1SATBCardTableModRefBS* ctbs() { return _ct_bs; } | |
86 | |
22901
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
87 InCSetState dest(InCSetState original) const { |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
88 assert(original.is_valid(), |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
89 err_msg("Original state invalid: " CSETSTATE_FORMAT, original.value())); |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
90 assert(_dest[original.value()].is_valid_gen(), |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
91 err_msg("Dest state is invalid: " CSETSTATE_FORMAT, _dest[original.value()].value())); |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
92 return _dest[original.value()]; |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
93 } |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
94 |
20224
a2328cbebb23
8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents:
20223
diff
changeset
|
95 public: |
20223 | 96 G1ParScanThreadState(G1CollectedHeap* g1h, uint queue_num, ReferenceProcessor* rp); |
20224
a2328cbebb23
8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents:
20223
diff
changeset
|
97 ~G1ParScanThreadState(); |
20223 | 98 |
99 ageTable* age_table() { return &_age_table; } | |
100 | |
101 #ifdef ASSERT | |
20224
a2328cbebb23
8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents:
20223
diff
changeset
|
102 bool queue_is_empty() const { return _refs->is_empty(); } |
a2328cbebb23
8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents:
20223
diff
changeset
|
103 |
20223 | 104 bool verify_ref(narrowOop* ref) const; |
105 bool verify_ref(oop* ref) const; | |
106 bool verify_task(StarTask ref) const; | |
107 #endif // ASSERT | |
108 | |
109 template <class T> void push_on_queue(T* ref) { | |
110 assert(verify_ref(ref), "sanity"); | |
20224
a2328cbebb23
8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents:
20223
diff
changeset
|
111 _refs->push(ref); |
20223 | 112 } |
113 | |
20504
6948da6d7c13
8052172: Evacuation failure handling in G1 does not evacuate all objects if -XX:-G1DeferredRSUpdate is set
tschatzl
parents:
20404
diff
changeset
|
114 template <class T> void update_rs(HeapRegion* from, T* p, int tid) { |
6948da6d7c13
8052172: Evacuation failure handling in G1 does not evacuate all objects if -XX:-G1DeferredRSUpdate is set
tschatzl
parents:
20404
diff
changeset
|
115 // If the new value of the field points to the same region or |
6948da6d7c13
8052172: Evacuation failure handling in G1 does not evacuate all objects if -XX:-G1DeferredRSUpdate is set
tschatzl
parents:
20404
diff
changeset
|
116 // is the to-space, we don't need to include it in the Rset updates. |
6948da6d7c13
8052172: Evacuation failure handling in G1 does not evacuate all objects if -XX:-G1DeferredRSUpdate is set
tschatzl
parents:
20404
diff
changeset
|
117 if (!from->is_in_reserved(oopDesc::load_decode_heap_oop(p)) && !from->is_survivor()) { |
6948da6d7c13
8052172: Evacuation failure handling in G1 does not evacuate all objects if -XX:-G1DeferredRSUpdate is set
tschatzl
parents:
20404
diff
changeset
|
118 size_t card_index = ctbs()->index_for(p); |
6948da6d7c13
8052172: Evacuation failure handling in G1 does not evacuate all objects if -XX:-G1DeferredRSUpdate is set
tschatzl
parents:
20404
diff
changeset
|
119 // If the card hasn't been added to the buffer, do it. |
6948da6d7c13
8052172: Evacuation failure handling in G1 does not evacuate all objects if -XX:-G1DeferredRSUpdate is set
tschatzl
parents:
20404
diff
changeset
|
120 if (ctbs()->mark_card_deferred(card_index)) { |
6948da6d7c13
8052172: Evacuation failure handling in G1 does not evacuate all objects if -XX:-G1DeferredRSUpdate is set
tschatzl
parents:
20404
diff
changeset
|
121 dirty_card_queue().enqueue((jbyte*)ctbs()->byte_for_index(card_index)); |
6948da6d7c13
8052172: Evacuation failure handling in G1 does not evacuate all objects if -XX:-G1DeferredRSUpdate is set
tschatzl
parents:
20404
diff
changeset
|
122 } |
6948da6d7c13
8052172: Evacuation failure handling in G1 does not evacuate all objects if -XX:-G1DeferredRSUpdate is set
tschatzl
parents:
20404
diff
changeset
|
123 } |
6948da6d7c13
8052172: Evacuation failure handling in G1 does not evacuate all objects if -XX:-G1DeferredRSUpdate is set
tschatzl
parents:
20404
diff
changeset
|
124 } |
20223 | 125 |
126 void set_evac_failure_closure(OopsInHeapRegionClosure* evac_failure_cl) { | |
127 _evac_failure_cl = evac_failure_cl; | |
128 } | |
20224
a2328cbebb23
8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents:
20223
diff
changeset
|
129 |
a2328cbebb23
8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents:
20223
diff
changeset
|
130 OopsInHeapRegionClosure* evac_failure_closure() { return _evac_failure_cl; } |
20223 | 131 |
132 int* hash_seed() { return &_hash_seed; } | |
133 uint queue_num() { return _queue_num; } | |
134 | |
135 size_t term_attempts() const { return _term_attempts; } | |
136 void note_term_attempt() { _term_attempts++; } | |
137 | |
138 void start_strong_roots() { | |
139 _start_strong_roots = os::elapsedTime(); | |
140 } | |
141 void end_strong_roots() { | |
142 _strong_roots_time += (os::elapsedTime() - _start_strong_roots); | |
143 } | |
144 double strong_roots_time() const { return _strong_roots_time; } | |
145 | |
146 void start_term_time() { | |
147 note_term_attempt(); | |
148 _start_term = os::elapsedTime(); | |
149 } | |
150 void end_term_time() { | |
151 _term_time += (os::elapsedTime() - _start_term); | |
152 } | |
153 double term_time() const { return _term_time; } | |
154 | |
155 double elapsed_time() const { | |
156 return os::elapsedTime() - _start; | |
157 } | |
158 | |
20224
a2328cbebb23
8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents:
20223
diff
changeset
|
159 static void print_termination_stats_hdr(outputStream* const st = gclog_or_tty); |
a2328cbebb23
8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents:
20223
diff
changeset
|
160 void print_termination_stats(int i, outputStream* const st = gclog_or_tty) const; |
20223 | 161 |
162 size_t* surviving_young_words() { | |
163 // We add on to hide entry 0 which accumulates surviving words for | |
164 // age -1 regions (i.e. non-young ones) | |
165 return _surviving_young_words; | |
166 } | |
167 | |
168 private: | |
169 #define G1_PARTIAL_ARRAY_MASK 0x2 | |
170 | |
171 inline bool has_partial_array_mask(oop* ref) const { | |
172 return ((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) == G1_PARTIAL_ARRAY_MASK; | |
173 } | |
174 | |
175 // We never encode partial array oops as narrowOop*, so return false immediately. | |
176 // This allows the compiler to create optimized code when popping references from | |
177 // the work queue. | |
178 inline bool has_partial_array_mask(narrowOop* ref) const { | |
179 assert(((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) != G1_PARTIAL_ARRAY_MASK, "Partial array oop reference encoded as narrowOop*"); | |
180 return false; | |
181 } | |
182 | |
183 // Only implement set_partial_array_mask() for regular oops, not for narrowOops. | |
184 // We always encode partial arrays as regular oop, to allow the | |
185 // specialization for has_partial_array_mask() for narrowOops above. | |
186 // This means that unintentional use of this method with narrowOops are caught | |
187 // by the compiler. | |
188 inline oop* set_partial_array_mask(oop obj) const { | |
189 assert(((uintptr_t)(void *)obj & G1_PARTIAL_ARRAY_MASK) == 0, "Information loss!"); | |
190 return (oop*) ((uintptr_t)(void *)obj | G1_PARTIAL_ARRAY_MASK); | |
191 } | |
192 | |
193 inline oop clear_partial_array_mask(oop* ref) const { | |
194 return cast_to_oop((intptr_t)ref & ~G1_PARTIAL_ARRAY_MASK); | |
195 } | |
196 | |
197 inline void do_oop_partial_array(oop* p); | |
198 | |
199 // This method is applied to the fields of the objects that have just been copied. | |
20224
a2328cbebb23
8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents:
20223
diff
changeset
|
200 template <class T> inline void do_oop_evac(T* p, HeapRegion* from); |
20223 | 201 |
20224
a2328cbebb23
8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents:
20223
diff
changeset
|
202 template <class T> inline void deal_with_reference(T* ref_to_scan); |
20223 | 203 |
20224
a2328cbebb23
8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents:
20223
diff
changeset
|
204 inline void dispatch_reference(StarTask ref); |
22901
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
205 |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
206 // Tries to allocate word_sz in the PLAB of the next "generation" after trying to |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
207 // allocate into dest. State is the original (source) cset state for the object |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
208 // that is allocated for. |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
209 // Returns a non-NULL pointer if successful, and updates dest if required. |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
210 HeapWord* allocate_in_next_plab(InCSetState const state, |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
211 InCSetState* dest, |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
212 size_t word_sz, |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
213 AllocationContext_t const context); |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
214 |
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
215 inline InCSetState next_state(InCSetState const state, markOop const m, uint& age); |
20224
a2328cbebb23
8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents:
20223
diff
changeset
|
216 public: |
20223 | 217 |
22901
c132be0fb74d
8060025: Object copy time regressions after JDK-8031323 and JDK-8057536
tschatzl
parents:
22895
diff
changeset
|
218 oop copy_to_survivor_space(InCSetState const state, oop const obj, markOop const old_mark); |
20223 | 219 |
20224
a2328cbebb23
8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents:
20223
diff
changeset
|
220 void trim_queue(); |
20223 | 221 |
20224
a2328cbebb23
8035401: Fix visibility of G1ParScanThreadState members
tschatzl
parents:
20223
diff
changeset
|
222 inline void steal_and_trim_queue(RefToScanQueueSet *task_queues); |
20223 | 223 }; |
224 | |
225 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1PARSCANTHREADSTATE_HPP |