< prev index next >

src/hotspot/share/gc/parallel/psTasks.cpp

8224663: Parallel GC: Use WorkGang (5: ScavengeRootsTask)

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 "aot/aotLoader.hpp"                                                                                               
26 #include "classfile/classLoaderDataGraph.hpp"                                                                              
27 #include "classfile/systemDictionary.hpp"                                                                                  
28 #include "code/codeCache.hpp"                                                                                              
29 #include "gc/parallel/gcTaskManager.hpp"                                                                                   
30 #include "gc/parallel/parallelScavengeHeap.inline.hpp"                                                                     
31 #include "gc/parallel/psCardTable.hpp"                                                                                     
32 #include "gc/parallel/psClosure.inline.hpp"                                                                                
33 #include "gc/parallel/psPromotionManager.hpp"                                                                              
34 #include "gc/parallel/psPromotionManager.inline.hpp"                                                                       
35 #include "gc/parallel/psScavenge.inline.hpp"                                                                               
36 #include "gc/parallel/psTasks.hpp"                                                                                         
37 #include "gc/shared/scavengableNMethods.hpp"                                                                               
38 #include "gc/shared/taskqueue.inline.hpp"                                                                                  
39 #include "memory/iterator.hpp"                                                                                             
40 #include "memory/resourceArea.hpp"                                                                                         
41 #include "memory/universe.hpp"                                                                                             
42 #include "oops/oop.inline.hpp"                                                                                             
43 #include "runtime/thread.hpp"                                                                                              
44 #include "runtime/vmThread.hpp"                                                                                            
45 #include "services/management.hpp"                                                                                         
46 #if INCLUDE_JVMCI                                                                                                          
47 #include "jvmci/jvmci.hpp"                                                                                                 
48 #endif                                                                                                                     
49                                                                                                                            
50 //                                                                                                                         
51 // ScavengeRootsTask                                                                                                       
52 //                                                                                                                         
53                                                                                                                            
54 void ScavengeRootsTask::do_it(GCTaskManager* manager, uint which) {                                                        
55   assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");                                               
56                                                                                                                            
57   PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);                                         
58   PSScavengeRootsClosure roots_closure(pm);                                                                                
59   PSPromoteRootsClosure  roots_to_old_closure(pm);                                                                         
60                                                                                                                            
61   switch (_root_type) {                                                                                                    
62     case universe:                                                                                                         
63       Universe::oops_do(&roots_closure);                                                                                   
64       break;                                                                                                               
65                                                                                                                            
66     case jni_handles:                                                                                                      
67       JNIHandles::oops_do(&roots_closure);                                                                                 
68       break;                                                                                                               
69                                                                                                                            
70     case threads:                                                                                                          
71     {                                                                                                                      
72       ResourceMark rm;                                                                                                     
73       Threads::oops_do(&roots_closure, NULL);                                                                              
74     }                                                                                                                      
75     break;                                                                                                                 
76                                                                                                                            
77     case object_synchronizer:                                                                                              
78       ObjectSynchronizer::oops_do(&roots_closure);                                                                         
79       break;                                                                                                               
80                                                                                                                            
81     case system_dictionary:                                                                                                
82       SystemDictionary::oops_do(&roots_closure);                                                                           
83       break;                                                                                                               
84                                                                                                                            
85     case class_loader_data:                                                                                                
86     {                                                                                                                      
87       PSScavengeCLDClosure cld_closure(pm);                                                                                
88       ClassLoaderDataGraph::cld_do(&cld_closure);                                                                          
89     }                                                                                                                      
90     break;                                                                                                                 
91                                                                                                                            
92     case management:                                                                                                       
93       Management::oops_do(&roots_closure);                                                                                 
94       break;                                                                                                               
95                                                                                                                            
96     case jvmti:                                                                                                            
97       JvmtiExport::oops_do(&roots_closure);                                                                                
98       break;                                                                                                               
99                                                                                                                            
100     case code_cache:                                                                                                       
101       {                                                                                                                    
102         MarkingCodeBlobClosure code_closure(&roots_to_old_closure, CodeBlobToOopClosure::FixRelocations);                  
103         ScavengableNMethods::nmethods_do(&code_closure);                                                                   
104         AOTLoader::oops_do(&roots_closure);                                                                                
105       }                                                                                                                    
106       break;                                                                                                               
107                                                                                                                            
108 #if INCLUDE_JVMCI                                                                                                          
109     case jvmci:                                                                                                            
110       JVMCI::oops_do(&roots_closure);                                                                                      
111       break;                                                                                                               
112 #endif                                                                                                                     
113                                                                                                                            
114     default:                                                                                                               
115       fatal("Unknown root type");                                                                                          
116   }                                                                                                                        
117                                                                                                                            
118   // Do the real work                                                                                                      
119   pm->drain_stacks(false);                                                                                                 
120 }                                                                                                                          
121                                                                                                                            
122 //                                                                                                                         
123 // ThreadRootsTask                                                                                                         
124 //                                                                                                                         
125                                                                                                                            
126 void ThreadRootsTask::do_it(GCTaskManager* manager, uint which) {                                                          
127   assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");                                               
128                                                                                                                            
129   PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);                                         
130   PSScavengeRootsClosure roots_closure(pm);                                                                                
131   MarkingCodeBlobClosure roots_in_blobs(&roots_closure, CodeBlobToOopClosure::FixRelocations);                             
132                                                                                                                            
133   _thread->oops_do(&roots_closure, &roots_in_blobs);                                                                       
134                                                                                                                            
135   // Do the real work                                                                                                      
136   pm->drain_stacks(false);                                                                                                 
137 }                                                                                                                          
138 
139 //                                                                                                                         
140 // StealTask                                                                                                               
141 //                                                                                                                         
142 
143 StealTask::StealTask(ParallelTaskTerminator* t) :                                                                          
144   _terminator(t) {}                                                                                                        
145 
146 void StealTask::do_it(GCTaskManager* manager, uint which) {                                                                
147   assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");                                               
148 
149   PSPromotionManager* pm =                                                                                                 
150     PSPromotionManager::gc_thread_promotion_manager(which);                                                                
151   pm->drain_stacks(true);                                                                                                  
152   guarantee(pm->stacks_empty(),                                                                                            
153             "stacks should be empty at this point");                                                                       
154 
155   while(true) {                                                                                                            
156     StarTask p;                                                                                                            
157     if (PSPromotionManager::steal_depth(which, p)) {                                                                       
158       TASKQUEUE_STATS_ONLY(pm->record_steal(p));                                                                           
159       pm->process_popped_location_depth(p);                                                                                
160       pm->drain_stacks_depth(true);                                                                                        
161     } else {                                                                                                               
162       if (terminator()->offer_termination()) {                                                                             
163         break;                                                                                                             
164       }                                                                                                                    
165     }                                                                                                                      
166   }                                                                                                                        
167   guarantee(pm->stacks_empty(), "stacks should be empty at this point");                                                   
168 }                                                                                                                          
169                                                                                                                            
170 //                                                                                                                         
171 // OldToYoungRootsTask                                                                                                     
172 //                                                                                                                         
173                                                                                                                            
174 void OldToYoungRootsTask::do_it(GCTaskManager* manager, uint which) {                                                      
175   // There are not old-to-young pointers if the old gen is empty.                                                          
176   assert(!_old_gen->object_space()->is_empty(),                                                                            
177     "Should not be called is there is no work");                                                                           
178   assert(_old_gen != NULL, "Sanity");                                                                                      
179   assert(_old_gen->object_space()->contains(_gen_top) || _gen_top == _old_gen->object_space()->top(), "Sanity");           
180   assert(_stripe_number < ParallelGCThreads, "Sanity");                                                                    
181                                                                                                                            
182   {                                                                                                                        
183     PSPromotionManager* pm = PSPromotionManager::gc_thread_promotion_manager(which);                                       
184     PSCardTable* card_table = ParallelScavengeHeap::heap()->card_table();                                                  
185                                                                                                                            
186     card_table->scavenge_contents_parallel(_old_gen->start_array(),                                                        
187                                            _old_gen->object_space(),                                                       
188                                            _gen_top,                                                                       
189                                            pm,                                                                             
190                                            _stripe_number,                                                                 
191                                            _stripe_total);                                                                 
192                                                                                                                            
193     // Do the real work                                                                                                    
194     pm->drain_stacks(false);                                                                                               
195   }                                                                                                                        
196 }                                                                                                                          

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 "classfile/systemDictionary.hpp"
26 #include "code/codeCache.hpp"
27 #include "gc/parallel/gcTaskManager.hpp"
28 #include "gc/parallel/parallelScavengeHeap.inline.hpp"
29 #include "gc/parallel/psCardTable.hpp"
30 #include "gc/parallel/psClosure.inline.hpp"
31 #include "gc/parallel/psPromotionManager.hpp"
32 #include "gc/parallel/psPromotionManager.inline.hpp"
33 #include "gc/parallel/psScavenge.inline.hpp"
34 #include "gc/parallel/psTasks.hpp"

35 #include "gc/shared/taskqueue.inline.hpp"
36 #include "memory/iterator.hpp"
37 #include "memory/resourceArea.hpp"
38 #include "memory/universe.hpp"
39 #include "oops/oop.inline.hpp"
40 #include "runtime/thread.hpp"
41 #include "runtime/vmThread.hpp"
42 #include "services/management.hpp"




























































































43 
44 //
45 // StealTask
46 //
47 
48 StealTask::StealTask(ParallelTaskTerminator* t) :
49   _terminator(t) {}
50 
51 void StealTask::do_it(GCTaskManager* manager, uint which) {
52   assert(ParallelScavengeHeap::heap()->is_gc_active(), "called outside gc");
53 
54   PSPromotionManager* pm =
55     PSPromotionManager::gc_thread_promotion_manager(which);
56   pm->drain_stacks(true);
57   guarantee(pm->stacks_empty(),
58             "stacks should be empty at this point");
59 
60   while(true) {
61     StarTask p;
62     if (PSPromotionManager::steal_depth(which, p)) {
63       TASKQUEUE_STATS_ONLY(pm->record_steal(p));
64       pm->process_popped_location_depth(p);
65       pm->drain_stacks_depth(true);
66     } else {
67       if (terminator()->offer_termination()) {
68         break;
69       }
70     }
71   }
72   guarantee(pm->stacks_empty(), "stacks should be empty at this point");




























73 }
< prev index next >