< prev index next >

src/hotspot/share/gc/g1/g1BarrierSet.cpp

include problems

G1BarrierSet_merge

5  * under the terms of the GNU General Public License version 2 only, as                                                              
6  * published by the Free Software Foundation.                                                                                        
7  *                                                                                                                                   
8  * This code is distributed in the hope that it will be useful, but WITHOUT                                                          
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or                                                             
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License                                                             
11  * version 2 for more details (a copy is included in the LICENSE file that                                                           
12  * accompanied this code).                                                                                                           
13  *                                                                                                                                   
14  * You should have received a copy of the GNU General Public License version                                                         
15  * 2 along with this work; if not, write to the Free Software Foundation,                                                            
16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.                                                                     
17  *                                                                                                                                   
18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA                                                           
19  * or visit www.oracle.com if you need additional information or have any                                                            
20  * questions.                                                                                                                        
21  *                                                                                                                                   
22  */                                                                                                                                  
23 
24 #include "precompiled.hpp"                                                                                                           
                                                                                                                                     
25 #include "gc/g1/g1CardTable.inline.hpp"                                                                                              
26 #include "gc/g1/g1CollectedHeap.inline.hpp"                                                                                          
27 #include "gc/g1/g1SATBCardTableModRefBS.inline.hpp"                                                                                  
28 #include "gc/g1/heapRegion.hpp"                                                                                                      
29 #include "gc/g1/satbMarkQueue.hpp"                                                                                                   
30 #include "logging/log.hpp"                                                                                                           
31 #include "oops/oop.inline.hpp"                                                                                                       
32 #include "runtime/mutexLocker.hpp"                                                                                                   
33 #include "runtime/thread.inline.hpp"                                                                                                 
34 
35 G1SATBCardTableModRefBS::G1SATBCardTableModRefBS(                                                                                    
36   G1CardTable* card_table,                                                                                                           
37   const BarrierSet::FakeRtti& fake_rtti) :                                                                                           
38   CardTableModRefBS(card_table, fake_rtti.add_tag(BarrierSet::G1SATBCT))                                                             
39 { }                                                                                                                                  
40 
41 void G1SATBCardTableModRefBS::enqueue(oop pre_val) {                                                                                 
42   // Nulls should have been already filtered.                                                                                        
43   assert(oopDesc::is_oop(pre_val, true), "Error");                                                                                   
44 
45   if (!JavaThread::satb_mark_queue_set().is_active()) return;                                                                        
46   Thread* thr = Thread::current();                                                                                                   
47   if (thr->is_Java_thread()) {                                                                                                       
48     JavaThread* jt = (JavaThread*)thr;                                                                                               
49     jt->satb_mark_queue().enqueue(pre_val);                                                                                          
50   } else {                                                                                                                           
51     MutexLockerEx x(Shared_SATB_Q_lock, Mutex::_no_safepoint_check_flag);                                                            
52     JavaThread::satb_mark_queue_set().shared_satb_queue()->enqueue(pre_val);                                                         
53   }                                                                                                                                  
54 }                                                                                                                                    
55 
56 template <class T> void                                                                                                              
57 G1SATBCardTableModRefBS::write_ref_array_pre_work(T* dst, int count) {                                                               
58   if (!JavaThread::satb_mark_queue_set().is_active()) return;                                                                        
59   T* elem_ptr = dst;                                                                                                                 
60   for (int i = 0; i < count; i++, elem_ptr++) {                                                                                      
61     T heap_oop = oopDesc::load_heap_oop(elem_ptr);                                                                                   
62     if (!oopDesc::is_null(heap_oop)) {                                                                                               
63       enqueue(oopDesc::decode_heap_oop_not_null(heap_oop));                                                                          
64     }                                                                                                                                
65   }                                                                                                                                  
66 }                                                                                                                                    
67 
68 void G1SATBCardTableModRefBS::write_ref_array_pre(oop* dst, int count, bool dest_uninitialized) {                                    
69   if (!dest_uninitialized) {                                                                                                         
70     write_ref_array_pre_work(dst, count);                                                                                            
71   }                                                                                                                                  
72 }                                                                                                                                    
73 
74 void G1SATBCardTableModRefBS::write_ref_array_pre(narrowOop* dst, int count, bool dest_uninitialized) {                              
75   if (!dest_uninitialized) {                                                                                                         
76     write_ref_array_pre_work(dst, count);                                                                                            
77   }                                                                                                                                  
78 }                                                                                                                                    
79 
80 G1SATBCardTableLoggingModRefBS::                                                                                                     
81 G1SATBCardTableLoggingModRefBS(G1CardTable* card_table) :                                                                            
82   G1SATBCardTableModRefBS(card_table, BarrierSet::FakeRtti(G1SATBCTLogging)),                                                        
83   _dcqs(JavaThread::dirty_card_queue_set()) {}                                                                                       
84                                                                                                                                      
85 void G1SATBCardTableLoggingModRefBS::write_ref_field_post_slow(volatile jbyte* byte) {                                               
86   // In the slow path, we know a card is not young                                                                                   
87   assert(*byte != G1CardTable::g1_young_card_val(), "slow path invoked without filtering");                                          
88   OrderAccess::storeload();                                                                                                          
89   if (*byte != G1CardTable::dirty_card_val()) {                                                                                      
90     *byte = G1CardTable::dirty_card_val();                                                                                           
91     Thread* thr = Thread::current();                                                                                                 
92     if (thr->is_Java_thread()) {                                                                                                     
93       JavaThread* jt = (JavaThread*)thr;                                                                                             
94       jt->dirty_card_queue().enqueue(byte);                                                                                          
95     } else {                                                                                                                         
96       MutexLockerEx x(Shared_DirtyCardQ_lock,                                                                                        
97                       Mutex::_no_safepoint_check_flag);                                                                              
98       _dcqs.shared_dirty_card_queue()->enqueue(byte);                                                                                
99     }                                                                                                                                
100   }                                                                                                                                  
101 }                                                                                                                                    
102 
103 void G1SATBCardTableLoggingModRefBS::invalidate(MemRegion mr) {                                                                      
104   if (mr.is_empty()) {                                                                                                               
105     return;                                                                                                                          
106   }                                                                                                                                  
107   volatile jbyte* byte = _card_table->byte_for(mr.start());                                                                          
108   jbyte* last_byte = _card_table->byte_for(mr.last());                                                                               
109   Thread* thr = Thread::current();                                                                                                   
110     // skip all consecutive young cards                                                                                              
111   for (; byte <= last_byte && *byte == G1CardTable::g1_young_card_val(); byte++);                                                    
112 
113   if (byte <= last_byte) {                                                                                                           
114     OrderAccess::storeload();                                                                                                        
115     // Enqueue if necessary.                                                                                                         
116     if (thr->is_Java_thread()) {                                                                                                     
117       JavaThread* jt = (JavaThread*)thr;                                                                                             
118       for (; byte <= last_byte; byte++) {                                                                                            
119         if (*byte == G1CardTable::g1_young_card_val()) {                                                                             
120           continue;                                                                                                                  
121         }                                                                                                                            
122         if (*byte != G1CardTable::dirty_card_val()) {                                                                                
123           *byte = G1CardTable::dirty_card_val();                                                                                     
124           jt->dirty_card_queue().enqueue(byte);                                                                                      
125         }                                                                                                                            
126       }                                                                                                                              
127     } else {                                                                                                                         
128       MutexLockerEx x(Shared_DirtyCardQ_lock,                                                                                        
129                       Mutex::_no_safepoint_check_flag);                                                                              
130       for (; byte <= last_byte; byte++) {                                                                                            
131         if (*byte == G1CardTable::g1_young_card_val()) {                                                                             
132           continue;                                                                                                                  
133         }                                                                                                                            
134         if (*byte != G1CardTable::dirty_card_val()) {                                                                                
135           *byte = G1CardTable::dirty_card_val();                                                                                     
136           _dcqs.shared_dirty_card_queue()->enqueue(byte);                                                                            
137         }                                                                                                                            
138       }                                                                                                                              
139     }                                                                                                                                
140   }                                                                                                                                  
141 }                                                                                                                                    
142 
143 void G1SATBCardTableLoggingModRefBS::on_thread_attach(JavaThread* thread) {                                                          
144   // This method initializes the SATB and dirty card queues before a                                                                 
145   // JavaThread is added to the Java thread list. Right now, we don't                                                                
146   // have to do anything to the dirty card queue (it should have been                                                                
147   // activated when the thread was created), but we have to activate                                                                 
148   // the SATB queue if the thread is created while a marking cycle is                                                                
149   // in progress. The activation / de-activation of the SATB queues at                                                               
150   // the beginning / end of a marking cycle is done during safepoints                                                                
151   // so we have to make sure this method is called outside one to be                                                                 
152   // able to safely read the active field of the SATB queue set. Right                                                               
153   // now, it is called just before the thread is added to the Java                                                                   
154   // thread list in the Threads::add() method. That method is holding                                                                
155   // the Threads_lock which ensures we are outside a safepoint. We                                                                   
156   // cannot do the obvious and set the active field of the SATB queue                                                                
157   // when the thread is created given that, in some cases, safepoints                                                                
158   // might happen between the JavaThread constructor being called and the                                                            
159   // thread being added to the Java thread list (an example of this is                                                               
160   // when the structure for the DestroyJavaVM thread is created).                                                                    
161   assert(!SafepointSynchronize::is_at_safepoint(), "We should not be at a safepoint");                                               
162   assert(!thread->satb_mark_queue().is_active(), "SATB queue should not be active");                                                 
163   assert(thread->satb_mark_queue().is_empty(), "SATB queue should be empty");                                                        
164   assert(thread->dirty_card_queue().is_active(), "Dirty card queue should be active");                                               
165 
166   // If we are creating the thread during a marking cycle, we should                                                                 
167   // set the active field of the SATB queue to true.                                                                                 
168   if (thread->satb_mark_queue_set().is_active()) {                                                                                   
169     thread->satb_mark_queue().set_active(true);                                                                                      
170   }                                                                                                                                  
171 }                                                                                                                                    
172 
173 void G1SATBCardTableLoggingModRefBS::on_thread_detach(JavaThread* thread) {                                                          
174   // Flush any deferred card marks, SATB buffers and dirty card queue buffers                                                        
175   CardTableModRefBS::on_thread_detach(thread);                                                                                       
176   thread->satb_mark_queue().flush();                                                                                                 
177   thread->dirty_card_queue().flush();                                                                                                
178 }                                                                                                                                    

5  * under the terms of the GNU General Public License version 2 only, as
6  * published by the Free Software Foundation.
7  *
8  * This code is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * version 2 for more details (a copy is included in the LICENSE file that
12  * accompanied this code).
13  *
14  * You should have received a copy of the GNU General Public License version
15  * 2 along with this work; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
19  * or visit www.oracle.com if you need additional information or have any
20  * questions.
21  *
22  */
23 
24 #include "precompiled.hpp"
25 #include "gc/g1/g1BarrierSet.inline.hpp"
26 #include "gc/g1/g1CardTable.inline.hpp"
27 #include "gc/g1/g1CollectedHeap.inline.hpp"

28 #include "gc/g1/heapRegion.hpp"
29 #include "gc/g1/satbMarkQueue.hpp"
30 #include "logging/log.hpp"
31 #include "oops/oop.inline.hpp"
32 #include "runtime/mutexLocker.hpp"
33 #include "runtime/thread.inline.hpp"
34 
35 G1BarrierSet::G1BarrierSet(G1CardTable* card_table) :
36   CardTableModRefBS(card_table, BarrierSet::FakeRtti(BarrierSet::G1BarrierSet)),
37   _dcqs(JavaThread::dirty_card_queue_set())

38 { }
39 
40 void G1BarrierSet::enqueue(oop pre_val) {
41   // Nulls should have been already filtered.
42   assert(oopDesc::is_oop(pre_val, true), "Error");
43 
44   if (!JavaThread::satb_mark_queue_set().is_active()) return;
45   Thread* thr = Thread::current();
46   if (thr->is_Java_thread()) {
47     JavaThread* jt = (JavaThread*)thr;
48     jt->satb_mark_queue().enqueue(pre_val);
49   } else {
50     MutexLockerEx x(Shared_SATB_Q_lock, Mutex::_no_safepoint_check_flag);
51     JavaThread::satb_mark_queue_set().shared_satb_queue()->enqueue(pre_val);
52   }
53 }
54 
55 template <class T> void
56 G1BarrierSet::write_ref_array_pre_work(T* dst, int count) {
57   if (!JavaThread::satb_mark_queue_set().is_active()) return;
58   T* elem_ptr = dst;
59   for (int i = 0; i < count; i++, elem_ptr++) {
60     T heap_oop = oopDesc::load_heap_oop(elem_ptr);
61     if (!oopDesc::is_null(heap_oop)) {
62       enqueue(oopDesc::decode_heap_oop_not_null(heap_oop));
63     }
64   }
65 }
66 
67 void G1BarrierSet::write_ref_array_pre(oop* dst, int count, bool dest_uninitialized) {
68   if (!dest_uninitialized) {
69     write_ref_array_pre_work(dst, count);
70   }
71 }
72 
73 void G1BarrierSet::write_ref_array_pre(narrowOop* dst, int count, bool dest_uninitialized) {
74   if (!dest_uninitialized) {
75     write_ref_array_pre_work(dst, count);
76   }
77 }
78 
79 void G1BarrierSet::write_ref_field_post_slow(volatile jbyte* byte) {





80   // In the slow path, we know a card is not young
81   assert(*byte != G1CardTable::g1_young_card_val(), "slow path invoked without filtering");
82   OrderAccess::storeload();
83   if (*byte != G1CardTable::dirty_card_val()) {
84     *byte = G1CardTable::dirty_card_val();
85     Thread* thr = Thread::current();
86     if (thr->is_Java_thread()) {
87       JavaThread* jt = (JavaThread*)thr;
88       jt->dirty_card_queue().enqueue(byte);
89     } else {
90       MutexLockerEx x(Shared_DirtyCardQ_lock,
91                       Mutex::_no_safepoint_check_flag);
92       _dcqs.shared_dirty_card_queue()->enqueue(byte);
93     }
94   }
95 }
96 
97 void G1BarrierSet::invalidate(MemRegion mr) {
98   if (mr.is_empty()) {
99     return;
100   }
101   volatile jbyte* byte = _card_table->byte_for(mr.start());
102   jbyte* last_byte = _card_table->byte_for(mr.last());
103   Thread* thr = Thread::current();
104     // skip all consecutive young cards
105   for (; byte <= last_byte && *byte == G1CardTable::g1_young_card_val(); byte++);
106 
107   if (byte <= last_byte) {
108     OrderAccess::storeload();
109     // Enqueue if necessary.
110     if (thr->is_Java_thread()) {
111       JavaThread* jt = (JavaThread*)thr;
112       for (; byte <= last_byte; byte++) {
113         if (*byte == G1CardTable::g1_young_card_val()) {
114           continue;
115         }
116         if (*byte != G1CardTable::dirty_card_val()) {
117           *byte = G1CardTable::dirty_card_val();
118           jt->dirty_card_queue().enqueue(byte);
119         }
120       }
121     } else {
122       MutexLockerEx x(Shared_DirtyCardQ_lock,
123                       Mutex::_no_safepoint_check_flag);
124       for (; byte <= last_byte; byte++) {
125         if (*byte == G1CardTable::g1_young_card_val()) {
126           continue;
127         }
128         if (*byte != G1CardTable::dirty_card_val()) {
129           *byte = G1CardTable::dirty_card_val();
130           _dcqs.shared_dirty_card_queue()->enqueue(byte);
131         }
132       }
133     }
134   }
135 }
136 
137 void G1BarrierSet::on_thread_attach(JavaThread* thread) {
138   // This method initializes the SATB and dirty card queues before a
139   // JavaThread is added to the Java thread list. Right now, we don't
140   // have to do anything to the dirty card queue (it should have been
141   // activated when the thread was created), but we have to activate
142   // the SATB queue if the thread is created while a marking cycle is
143   // in progress. The activation / de-activation of the SATB queues at
144   // the beginning / end of a marking cycle is done during safepoints
145   // so we have to make sure this method is called outside one to be
146   // able to safely read the active field of the SATB queue set. Right
147   // now, it is called just before the thread is added to the Java
148   // thread list in the Threads::add() method. That method is holding
149   // the Threads_lock which ensures we are outside a safepoint. We
150   // cannot do the obvious and set the active field of the SATB queue
151   // when the thread is created given that, in some cases, safepoints
152   // might happen between the JavaThread constructor being called and the
153   // thread being added to the Java thread list (an example of this is
154   // when the structure for the DestroyJavaVM thread is created).
155   assert(!SafepointSynchronize::is_at_safepoint(), "We should not be at a safepoint");
156   assert(!thread->satb_mark_queue().is_active(), "SATB queue should not be active");
157   assert(thread->satb_mark_queue().is_empty(), "SATB queue should be empty");
158   assert(thread->dirty_card_queue().is_active(), "Dirty card queue should be active");
159 
160   // If we are creating the thread during a marking cycle, we should
161   // set the active field of the SATB queue to true.
162   if (thread->satb_mark_queue_set().is_active()) {
163     thread->satb_mark_queue().set_active(true);
164   }
165 }
166 
167 void G1BarrierSet::on_thread_detach(JavaThread* thread) {
168   // Flush any deferred card marks, SATB buffers and dirty card queue buffers
169   CardTableModRefBS::on_thread_detach(thread);
170   thread->satb_mark_queue().flush();
171   thread->dirty_card_queue().flush();
172 }
< prev index next >