1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/gc_implementation/g1/g1ParScanThreadState.hpp Mon Jul 21 09:41:04 2014 +0200 1.3 @@ -0,0 +1,292 @@ 1.4 +/* 1.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_G1PARSCANTHREADSTATE_HPP 1.29 +#define SHARE_VM_GC_IMPLEMENTATION_G1_G1PARSCANTHREADSTATE_HPP 1.30 + 1.31 +#include "gc_implementation/g1/dirtyCardQueue.hpp" 1.32 +#include "gc_implementation/g1/g1SATBCardTableModRefBS.hpp" 1.33 +#include "gc_implementation/g1/g1CollectedHeap.hpp" 1.34 +#include "gc_implementation/g1/g1CollectorPolicy.hpp" 1.35 +#include "gc_implementation/g1/g1OopClosures.hpp" 1.36 +#include "gc_implementation/g1/g1RemSet.hpp" 1.37 +#include "gc_implementation/shared/ageTable.hpp" 1.38 +#include "memory/allocation.hpp" 1.39 +#include "oops/oop.hpp" 1.40 + 1.41 +class HeapRegion; 1.42 +class outputStream; 1.43 + 1.44 +class G1ParScanThreadState : public StackObj { 1.45 +protected: 1.46 + G1CollectedHeap* _g1h; 1.47 + RefToScanQueue* _refs; 1.48 + DirtyCardQueue _dcq; 1.49 + G1SATBCardTableModRefBS* _ct_bs; 1.50 + G1RemSet* _g1_rem; 1.51 + 1.52 + G1ParGCAllocBuffer _surviving_alloc_buffer; 1.53 + G1ParGCAllocBuffer _tenured_alloc_buffer; 1.54 + G1ParGCAllocBuffer* _alloc_buffers[GCAllocPurposeCount]; 1.55 + ageTable _age_table; 1.56 + 1.57 + G1ParScanClosure _scanner; 1.58 + 1.59 + size_t _alloc_buffer_waste; 1.60 + size_t _undo_waste; 1.61 + 1.62 + OopsInHeapRegionClosure* _evac_failure_cl; 1.63 + 1.64 + int _hash_seed; 1.65 + uint _queue_num; 1.66 + 1.67 + size_t _term_attempts; 1.68 + 1.69 + double _start; 1.70 + double _start_strong_roots; 1.71 + double _strong_roots_time; 1.72 + double _start_term; 1.73 + double _term_time; 1.74 + 1.75 + // Map from young-age-index (0 == not young, 1 is youngest) to 1.76 + // surviving words. base is what we get back from the malloc call 1.77 + size_t* _surviving_young_words_base; 1.78 + // this points into the array, as we use the first few entries for padding 1.79 + size_t* _surviving_young_words; 1.80 + 1.81 +#define PADDING_ELEM_NUM (DEFAULT_CACHE_LINE_SIZE / sizeof(size_t)) 1.82 + 1.83 + void add_to_alloc_buffer_waste(size_t waste) { _alloc_buffer_waste += waste; } 1.84 + 1.85 + void add_to_undo_waste(size_t waste) { _undo_waste += waste; } 1.86 + 1.87 + DirtyCardQueue& dirty_card_queue() { return _dcq; } 1.88 + G1SATBCardTableModRefBS* ctbs() { return _ct_bs; } 1.89 + 1.90 + template <class T> inline void immediate_rs_update(HeapRegion* from, T* p, int tid); 1.91 + 1.92 + template <class T> void deferred_rs_update(HeapRegion* from, T* p, int tid) { 1.93 + // If the new value of the field points to the same region or 1.94 + // is the to-space, we don't need to include it in the Rset updates. 1.95 + if (!from->is_in_reserved(oopDesc::load_decode_heap_oop(p)) && !from->is_survivor()) { 1.96 + size_t card_index = ctbs()->index_for(p); 1.97 + // If the card hasn't been added to the buffer, do it. 1.98 + if (ctbs()->mark_card_deferred(card_index)) { 1.99 + dirty_card_queue().enqueue((jbyte*)ctbs()->byte_for_index(card_index)); 1.100 + } 1.101 + } 1.102 + } 1.103 + 1.104 +public: 1.105 + G1ParScanThreadState(G1CollectedHeap* g1h, uint queue_num, ReferenceProcessor* rp); 1.106 + ~G1ParScanThreadState() { 1.107 + retire_alloc_buffers(); 1.108 + FREE_C_HEAP_ARRAY(size_t, _surviving_young_words_base, mtGC); 1.109 + } 1.110 + 1.111 + RefToScanQueue* refs() { return _refs; } 1.112 + ageTable* age_table() { return &_age_table; } 1.113 + 1.114 + G1ParGCAllocBuffer* alloc_buffer(GCAllocPurpose purpose) { 1.115 + return _alloc_buffers[purpose]; 1.116 + } 1.117 + 1.118 + size_t alloc_buffer_waste() const { return _alloc_buffer_waste; } 1.119 + size_t undo_waste() const { return _undo_waste; } 1.120 + 1.121 +#ifdef ASSERT 1.122 + bool verify_ref(narrowOop* ref) const; 1.123 + bool verify_ref(oop* ref) const; 1.124 + bool verify_task(StarTask ref) const; 1.125 +#endif // ASSERT 1.126 + 1.127 + template <class T> void push_on_queue(T* ref) { 1.128 + assert(verify_ref(ref), "sanity"); 1.129 + refs()->push(ref); 1.130 + } 1.131 + 1.132 + template <class T> inline void update_rs(HeapRegion* from, T* p, int tid); 1.133 + 1.134 + HeapWord* allocate_slow(GCAllocPurpose purpose, size_t word_sz) { 1.135 + HeapWord* obj = NULL; 1.136 + size_t gclab_word_size = _g1h->desired_plab_sz(purpose); 1.137 + if (word_sz * 100 < gclab_word_size * ParallelGCBufferWastePct) { 1.138 + G1ParGCAllocBuffer* alloc_buf = alloc_buffer(purpose); 1.139 + add_to_alloc_buffer_waste(alloc_buf->words_remaining()); 1.140 + alloc_buf->retire(false /* end_of_gc */, false /* retain */); 1.141 + 1.142 + HeapWord* buf = _g1h->par_allocate_during_gc(purpose, gclab_word_size); 1.143 + if (buf == NULL) return NULL; // Let caller handle allocation failure. 1.144 + // Otherwise. 1.145 + alloc_buf->set_word_size(gclab_word_size); 1.146 + alloc_buf->set_buf(buf); 1.147 + 1.148 + obj = alloc_buf->allocate(word_sz); 1.149 + assert(obj != NULL, "buffer was definitely big enough..."); 1.150 + } else { 1.151 + obj = _g1h->par_allocate_during_gc(purpose, word_sz); 1.152 + } 1.153 + return obj; 1.154 + } 1.155 + 1.156 + HeapWord* allocate(GCAllocPurpose purpose, size_t word_sz) { 1.157 + HeapWord* obj = alloc_buffer(purpose)->allocate(word_sz); 1.158 + if (obj != NULL) return obj; 1.159 + return allocate_slow(purpose, word_sz); 1.160 + } 1.161 + 1.162 + void undo_allocation(GCAllocPurpose purpose, HeapWord* obj, size_t word_sz) { 1.163 + if (alloc_buffer(purpose)->contains(obj)) { 1.164 + assert(alloc_buffer(purpose)->contains(obj + word_sz - 1), 1.165 + "should contain whole object"); 1.166 + alloc_buffer(purpose)->undo_allocation(obj, word_sz); 1.167 + } else { 1.168 + CollectedHeap::fill_with_object(obj, word_sz); 1.169 + add_to_undo_waste(word_sz); 1.170 + } 1.171 + } 1.172 + 1.173 + void set_evac_failure_closure(OopsInHeapRegionClosure* evac_failure_cl) { 1.174 + _evac_failure_cl = evac_failure_cl; 1.175 + } 1.176 + OopsInHeapRegionClosure* evac_failure_closure() { 1.177 + return _evac_failure_cl; 1.178 + } 1.179 + 1.180 + int* hash_seed() { return &_hash_seed; } 1.181 + uint queue_num() { return _queue_num; } 1.182 + 1.183 + size_t term_attempts() const { return _term_attempts; } 1.184 + void note_term_attempt() { _term_attempts++; } 1.185 + 1.186 + void start_strong_roots() { 1.187 + _start_strong_roots = os::elapsedTime(); 1.188 + } 1.189 + void end_strong_roots() { 1.190 + _strong_roots_time += (os::elapsedTime() - _start_strong_roots); 1.191 + } 1.192 + double strong_roots_time() const { return _strong_roots_time; } 1.193 + 1.194 + void start_term_time() { 1.195 + note_term_attempt(); 1.196 + _start_term = os::elapsedTime(); 1.197 + } 1.198 + void end_term_time() { 1.199 + _term_time += (os::elapsedTime() - _start_term); 1.200 + } 1.201 + double term_time() const { return _term_time; } 1.202 + 1.203 + double elapsed_time() const { 1.204 + return os::elapsedTime() - _start; 1.205 + } 1.206 + 1.207 + static void 1.208 + print_termination_stats_hdr(outputStream* const st = gclog_or_tty); 1.209 + void 1.210 + print_termination_stats(int i, outputStream* const st = gclog_or_tty) const; 1.211 + 1.212 + size_t* surviving_young_words() { 1.213 + // We add on to hide entry 0 which accumulates surviving words for 1.214 + // age -1 regions (i.e. non-young ones) 1.215 + return _surviving_young_words; 1.216 + } 1.217 + 1.218 + private: 1.219 + void retire_alloc_buffers() { 1.220 + for (int ap = 0; ap < GCAllocPurposeCount; ++ap) { 1.221 + size_t waste = _alloc_buffers[ap]->words_remaining(); 1.222 + add_to_alloc_buffer_waste(waste); 1.223 + _alloc_buffers[ap]->flush_stats_and_retire(_g1h->stats_for_purpose((GCAllocPurpose)ap), 1.224 + true /* end_of_gc */, 1.225 + false /* retain */); 1.226 + } 1.227 + } 1.228 + 1.229 + #define G1_PARTIAL_ARRAY_MASK 0x2 1.230 + 1.231 + inline bool has_partial_array_mask(oop* ref) const { 1.232 + return ((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) == G1_PARTIAL_ARRAY_MASK; 1.233 + } 1.234 + 1.235 + // We never encode partial array oops as narrowOop*, so return false immediately. 1.236 + // This allows the compiler to create optimized code when popping references from 1.237 + // the work queue. 1.238 + inline bool has_partial_array_mask(narrowOop* ref) const { 1.239 + assert(((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) != G1_PARTIAL_ARRAY_MASK, "Partial array oop reference encoded as narrowOop*"); 1.240 + return false; 1.241 + } 1.242 + 1.243 + // Only implement set_partial_array_mask() for regular oops, not for narrowOops. 1.244 + // We always encode partial arrays as regular oop, to allow the 1.245 + // specialization for has_partial_array_mask() for narrowOops above. 1.246 + // This means that unintentional use of this method with narrowOops are caught 1.247 + // by the compiler. 1.248 + inline oop* set_partial_array_mask(oop obj) const { 1.249 + assert(((uintptr_t)(void *)obj & G1_PARTIAL_ARRAY_MASK) == 0, "Information loss!"); 1.250 + return (oop*) ((uintptr_t)(void *)obj | G1_PARTIAL_ARRAY_MASK); 1.251 + } 1.252 + 1.253 + inline oop clear_partial_array_mask(oop* ref) const { 1.254 + return cast_to_oop((intptr_t)ref & ~G1_PARTIAL_ARRAY_MASK); 1.255 + } 1.256 + 1.257 + inline void do_oop_partial_array(oop* p); 1.258 + 1.259 + // This method is applied to the fields of the objects that have just been copied. 1.260 + template <class T> void do_oop_evac(T* p, HeapRegion* from) { 1.261 + assert(!oopDesc::is_null(oopDesc::load_decode_heap_oop(p)), 1.262 + "Reference should not be NULL here as such are never pushed to the task queue."); 1.263 + oop obj = oopDesc::load_decode_heap_oop_not_null(p); 1.264 + 1.265 + // Although we never intentionally push references outside of the collection 1.266 + // set, due to (benign) races in the claim mechanism during RSet scanning more 1.267 + // than one thread might claim the same card. So the same card may be 1.268 + // processed multiple times. So redo this check. 1.269 + if (_g1h->in_cset_fast_test(obj)) { 1.270 + oop forwardee; 1.271 + if (obj->is_forwarded()) { 1.272 + forwardee = obj->forwardee(); 1.273 + } else { 1.274 + forwardee = copy_to_survivor_space(obj); 1.275 + } 1.276 + assert(forwardee != NULL, "forwardee should not be NULL"); 1.277 + oopDesc::encode_store_heap_oop(p, forwardee); 1.278 + } 1.279 + 1.280 + assert(obj != NULL, "Must be"); 1.281 + update_rs(from, p, queue_num()); 1.282 + } 1.283 +public: 1.284 + 1.285 + oop copy_to_survivor_space(oop const obj); 1.286 + 1.287 + template <class T> inline void deal_with_reference(T* ref_to_scan); 1.288 + 1.289 + inline void deal_with_reference(StarTask ref); 1.290 + 1.291 +public: 1.292 + void trim_queue(); 1.293 +}; 1.294 + 1.295 +#endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1PARSCANTHREADSTATE_HPP