g1ParScanThreadState.hpp (8869:ad916ca3715b) | g1ParScanThreadState.hpp (8870:57093b085a8f) |
---|---|
1/* 2 * Copyright (c) 2014, 2015, 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_G1_G1PARSCANTHREADSTATE_HPP 26#define SHARE_VM_GC_G1_G1PARSCANTHREADSTATE_HPP 27 28#include "gc/g1/dirtyCardQueue.hpp" 29#include "gc/g1/g1CollectedHeap.hpp" 30#include "gc/g1/g1CollectorPolicy.hpp" 31#include "gc/g1/g1OopClosures.hpp" 32#include "gc/g1/g1RemSet.hpp" 33#include "gc/g1/g1SATBCardTableModRefBS.hpp" 34#include "gc/shared/ageTable.hpp" 35#include "memory/allocation.hpp" 36#include "oops/oop.hpp" 37 38class G1PLABAllocator; 39class HeapRegion; 40class outputStream; 41 42class G1ParScanThreadState : public CHeapObj<mtGC> { 43 private: 44 G1CollectedHeap* _g1h; 45 RefToScanQueue* _refs; 46 DirtyCardQueue _dcq; 47 G1SATBCardTableModRefBS* _ct_bs; 48 G1RemSet* _g1_rem; 49 50 G1PLABAllocator* _plab_allocator; 51 52 ageTable _age_table; 53 InCSetState _dest[InCSetState::Num]; 54 // Local tenuring threshold. 55 uint _tenuring_threshold; 56 G1ParScanClosure _scanner; 57 58 int _hash_seed; 59 uint _worker_id; 60 61 // Map from young-age-index (0 == not young, 1 is youngest) to 62 // surviving words. base is what we get back from the malloc call 63 size_t* _surviving_young_words_base; 64 // this points into the array, as we use the first few entries for padding 65 size_t* _surviving_young_words; 66 67 // Indicates whether in the last generation (old) there is no more space 68 // available for allocation. 69 bool _old_gen_is_full; 70 71#define PADDING_ELEM_NUM (DEFAULT_CACHE_LINE_SIZE / sizeof(size_t)) 72 73 DirtyCardQueue& dirty_card_queue() { return _dcq; } 74 G1SATBCardTableModRefBS* ctbs() { return _ct_bs; } 75 76 InCSetState dest(InCSetState original) const { 77 assert(original.is_valid(), 78 err_msg("Original state invalid: " CSETSTATE_FORMAT, original.value())); 79 assert(_dest[original.value()].is_valid_gen(), 80 err_msg("Dest state is invalid: " CSETSTATE_FORMAT, _dest[original.value()].value())); 81 return _dest[original.value()]; 82 } 83 84 public: 85 G1ParScanThreadState(G1CollectedHeap* g1h, uint worker_id); 86 ~G1ParScanThreadState(); 87 88 void set_ref_processor(ReferenceProcessor* rp) { _scanner.set_ref_processor(rp); } 89 | 1/* 2 * Copyright (c) 2014, 2015, 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_G1_G1PARSCANTHREADSTATE_HPP 26#define SHARE_VM_GC_G1_G1PARSCANTHREADSTATE_HPP 27 28#include "gc/g1/dirtyCardQueue.hpp" 29#include "gc/g1/g1CollectedHeap.hpp" 30#include "gc/g1/g1CollectorPolicy.hpp" 31#include "gc/g1/g1OopClosures.hpp" 32#include "gc/g1/g1RemSet.hpp" 33#include "gc/g1/g1SATBCardTableModRefBS.hpp" 34#include "gc/shared/ageTable.hpp" 35#include "memory/allocation.hpp" 36#include "oops/oop.hpp" 37 38class G1PLABAllocator; 39class HeapRegion; 40class outputStream; 41 42class G1ParScanThreadState : public CHeapObj<mtGC> { 43 private: 44 G1CollectedHeap* _g1h; 45 RefToScanQueue* _refs; 46 DirtyCardQueue _dcq; 47 G1SATBCardTableModRefBS* _ct_bs; 48 G1RemSet* _g1_rem; 49 50 G1PLABAllocator* _plab_allocator; 51 52 ageTable _age_table; 53 InCSetState _dest[InCSetState::Num]; 54 // Local tenuring threshold. 55 uint _tenuring_threshold; 56 G1ParScanClosure _scanner; 57 58 int _hash_seed; 59 uint _worker_id; 60 61 // Map from young-age-index (0 == not young, 1 is youngest) to 62 // surviving words. base is what we get back from the malloc call 63 size_t* _surviving_young_words_base; 64 // this points into the array, as we use the first few entries for padding 65 size_t* _surviving_young_words; 66 67 // Indicates whether in the last generation (old) there is no more space 68 // available for allocation. 69 bool _old_gen_is_full; 70 71#define PADDING_ELEM_NUM (DEFAULT_CACHE_LINE_SIZE / sizeof(size_t)) 72 73 DirtyCardQueue& dirty_card_queue() { return _dcq; } 74 G1SATBCardTableModRefBS* ctbs() { return _ct_bs; } 75 76 InCSetState dest(InCSetState original) const { 77 assert(original.is_valid(), 78 err_msg("Original state invalid: " CSETSTATE_FORMAT, original.value())); 79 assert(_dest[original.value()].is_valid_gen(), 80 err_msg("Dest state is invalid: " CSETSTATE_FORMAT, _dest[original.value()].value())); 81 return _dest[original.value()]; 82 } 83 84 public: 85 G1ParScanThreadState(G1CollectedHeap* g1h, uint worker_id); 86 ~G1ParScanThreadState(); 87 88 void set_ref_processor(ReferenceProcessor* rp) { _scanner.set_ref_processor(rp); } 89 |
90 ageTable* age_table() { return &_age_table; } 91 | |
92#ifdef ASSERT 93 bool queue_is_empty() const { return _refs->is_empty(); } 94 95 bool verify_ref(narrowOop* ref) const; 96 bool verify_ref(oop* ref) const; 97 bool verify_task(StarTask ref) const; 98#endif // ASSERT 99 100 template <class T> void push_on_queue(T* ref); 101 102 template <class T> void update_rs(HeapRegion* from, T* p, uint tid) { 103 // If the new value of the field points to the same region or 104 // is the to-space, we don't need to include it in the Rset updates. 105 if (!from->is_in_reserved(oopDesc::load_decode_heap_oop(p)) && !from->is_survivor()) { 106 size_t card_index = ctbs()->index_for(p); 107 // If the card hasn't been added to the buffer, do it. 108 if (ctbs()->mark_card_deferred(card_index)) { 109 dirty_card_queue().enqueue((jbyte*)ctbs()->byte_for_index(card_index)); 110 } 111 } 112 } 113 114 uint worker_id() { return _worker_id; } 115 116 // Returns the current amount of waste due to alignment or not being able to fit 117 // objects within LABs and the undo waste. 118 virtual void waste(size_t& wasted, size_t& undo_wasted); 119 120 size_t* surviving_young_words() { 121 // We add one to hide entry 0 which accumulates surviving words for 122 // age -1 regions (i.e. non-young ones) 123 return _surviving_young_words + 1; 124 } 125 126 private: 127 #define G1_PARTIAL_ARRAY_MASK 0x2 128 129 inline bool has_partial_array_mask(oop* ref) const { 130 return ((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) == G1_PARTIAL_ARRAY_MASK; 131 } 132 133 // We never encode partial array oops as narrowOop*, so return false immediately. 134 // This allows the compiler to create optimized code when popping references from 135 // the work queue. 136 inline bool has_partial_array_mask(narrowOop* ref) const { 137 assert(((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) != G1_PARTIAL_ARRAY_MASK, "Partial array oop reference encoded as narrowOop*"); 138 return false; 139 } 140 141 // Only implement set_partial_array_mask() for regular oops, not for narrowOops. 142 // We always encode partial arrays as regular oop, to allow the 143 // specialization for has_partial_array_mask() for narrowOops above. 144 // This means that unintentional use of this method with narrowOops are caught 145 // by the compiler. 146 inline oop* set_partial_array_mask(oop obj) const { 147 assert(((uintptr_t)(void *)obj & G1_PARTIAL_ARRAY_MASK) == 0, "Information loss!"); 148 return (oop*) ((uintptr_t)(void *)obj | G1_PARTIAL_ARRAY_MASK); 149 } 150 151 inline oop clear_partial_array_mask(oop* ref) const { 152 return cast_to_oop((intptr_t)ref & ~G1_PARTIAL_ARRAY_MASK); 153 } 154 155 inline void do_oop_partial_array(oop* p); 156 157 // This method is applied to the fields of the objects that have just been copied. 158 template <class T> inline void do_oop_evac(T* p, HeapRegion* from); 159 160 template <class T> inline void deal_with_reference(T* ref_to_scan); 161 162 inline void dispatch_reference(StarTask ref); 163 164 // Tries to allocate word_sz in the PLAB of the next "generation" after trying to 165 // allocate into dest. State is the original (source) cset state for the object 166 // that is allocated for. Previous_plab_refill_failed indicates whether previously 167 // a PLAB refill into "state" failed. 168 // Returns a non-NULL pointer if successful, and updates dest if required. 169 // Also determines whether we should continue to try to allocate into the various 170 // generations or just end trying to allocate. 171 HeapWord* allocate_in_next_plab(InCSetState const state, 172 InCSetState* dest, 173 size_t word_sz, 174 AllocationContext_t const context, 175 bool previous_plab_refill_failed); 176 177 inline InCSetState next_state(InCSetState const state, markOop const m, uint& age); 178 public: 179 180 oop copy_to_survivor_space(InCSetState const state, oop const obj, markOop const old_mark); 181 182 void trim_queue(); 183 184 inline void steal_and_trim_queue(RefToScanQueueSet *task_queues); 185 186 // An attempt to evacuate "obj" has failed; take necessary steps. 187 oop handle_evacuation_failure_par(oop obj, markOop m); 188}; 189 190#endif // SHARE_VM_GC_G1_G1PARSCANTHREADSTATE_HPP | 90#ifdef ASSERT 91 bool queue_is_empty() const { return _refs->is_empty(); } 92 93 bool verify_ref(narrowOop* ref) const; 94 bool verify_ref(oop* ref) const; 95 bool verify_task(StarTask ref) const; 96#endif // ASSERT 97 98 template <class T> void push_on_queue(T* ref); 99 100 template <class T> void update_rs(HeapRegion* from, T* p, uint tid) { 101 // If the new value of the field points to the same region or 102 // is the to-space, we don't need to include it in the Rset updates. 103 if (!from->is_in_reserved(oopDesc::load_decode_heap_oop(p)) && !from->is_survivor()) { 104 size_t card_index = ctbs()->index_for(p); 105 // If the card hasn't been added to the buffer, do it. 106 if (ctbs()->mark_card_deferred(card_index)) { 107 dirty_card_queue().enqueue((jbyte*)ctbs()->byte_for_index(card_index)); 108 } 109 } 110 } 111 112 uint worker_id() { return _worker_id; } 113 114 // Returns the current amount of waste due to alignment or not being able to fit 115 // objects within LABs and the undo waste. 116 virtual void waste(size_t& wasted, size_t& undo_wasted); 117 118 size_t* surviving_young_words() { 119 // We add one to hide entry 0 which accumulates surviving words for 120 // age -1 regions (i.e. non-young ones) 121 return _surviving_young_words + 1; 122 } 123 124 private: 125 #define G1_PARTIAL_ARRAY_MASK 0x2 126 127 inline bool has_partial_array_mask(oop* ref) const { 128 return ((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) == G1_PARTIAL_ARRAY_MASK; 129 } 130 131 // We never encode partial array oops as narrowOop*, so return false immediately. 132 // This allows the compiler to create optimized code when popping references from 133 // the work queue. 134 inline bool has_partial_array_mask(narrowOop* ref) const { 135 assert(((uintptr_t)ref & G1_PARTIAL_ARRAY_MASK) != G1_PARTIAL_ARRAY_MASK, "Partial array oop reference encoded as narrowOop*"); 136 return false; 137 } 138 139 // Only implement set_partial_array_mask() for regular oops, not for narrowOops. 140 // We always encode partial arrays as regular oop, to allow the 141 // specialization for has_partial_array_mask() for narrowOops above. 142 // This means that unintentional use of this method with narrowOops are caught 143 // by the compiler. 144 inline oop* set_partial_array_mask(oop obj) const { 145 assert(((uintptr_t)(void *)obj & G1_PARTIAL_ARRAY_MASK) == 0, "Information loss!"); 146 return (oop*) ((uintptr_t)(void *)obj | G1_PARTIAL_ARRAY_MASK); 147 } 148 149 inline oop clear_partial_array_mask(oop* ref) const { 150 return cast_to_oop((intptr_t)ref & ~G1_PARTIAL_ARRAY_MASK); 151 } 152 153 inline void do_oop_partial_array(oop* p); 154 155 // This method is applied to the fields of the objects that have just been copied. 156 template <class T> inline void do_oop_evac(T* p, HeapRegion* from); 157 158 template <class T> inline void deal_with_reference(T* ref_to_scan); 159 160 inline void dispatch_reference(StarTask ref); 161 162 // Tries to allocate word_sz in the PLAB of the next "generation" after trying to 163 // allocate into dest. State is the original (source) cset state for the object 164 // that is allocated for. Previous_plab_refill_failed indicates whether previously 165 // a PLAB refill into "state" failed. 166 // Returns a non-NULL pointer if successful, and updates dest if required. 167 // Also determines whether we should continue to try to allocate into the various 168 // generations or just end trying to allocate. 169 HeapWord* allocate_in_next_plab(InCSetState const state, 170 InCSetState* dest, 171 size_t word_sz, 172 AllocationContext_t const context, 173 bool previous_plab_refill_failed); 174 175 inline InCSetState next_state(InCSetState const state, markOop const m, uint& age); 176 public: 177 178 oop copy_to_survivor_space(InCSetState const state, oop const obj, markOop const old_mark); 179 180 void trim_queue(); 181 182 inline void steal_and_trim_queue(RefToScanQueueSet *task_queues); 183 184 // An attempt to evacuate "obj" has failed; take necessary steps. 185 oop handle_evacuation_failure_par(oop obj, markOop m); 186}; 187 188#endif // SHARE_VM_GC_G1_G1PARSCANTHREADSTATE_HPP |