< prev index next >

src/hotspot/share/gc/parallel/psCompactionManager.inline.hpp

8211446_01: revision due to comments from StefanJ and Thomas

8211446: Replace oop_pc_follow_contents with oop_iterate and closure

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 #ifndef SHARE_VM_GC_PARALLEL_PSCOMPACTIONMANAGER_INLINE_HPP                                                                
25 #define SHARE_VM_GC_PARALLEL_PSCOMPACTIONMANAGER_INLINE_HPP                                                                
26 
                                                                                                                           
27 #include "gc/parallel/parMarkBitMap.hpp"                                                                                   
28 #include "gc/parallel/psCompactionManager.hpp"                                                                             
29 #include "gc/parallel/psParallelCompact.inline.hpp"                                                                        
30 #include "gc/shared/taskqueue.inline.hpp"                                                                                  
31 #include "oops/access.inline.hpp"                                                                                          
32 #include "oops/arrayOop.inline.hpp"                                                                                        
33 #include "oops/compressedOops.inline.hpp"                                                                                  
34 #include "oops/objArrayOop.inline.hpp"                                                                                     
35 #include "oops/oop.inline.hpp"                                                                                             
36 #include "utilities/debug.hpp"                                                                                             
37 #include "utilities/globalDefinitions.hpp"                                                                                 
38 
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
39 inline bool ParCompactionManager::steal(int queue_num, oop& t) {                                                           
40   return stack_array()->steal(queue_num, t);                                                                               
41 }                                                                                                                          
42 
43 inline bool ParCompactionManager::steal_objarray(int queue_num, ObjArrayTask& t) {                                         
44   return _objarray_queues->steal(queue_num, t);                                                                            
45 }                                                                                                                          
46 
47 inline bool ParCompactionManager::steal(int queue_num, size_t& region) {                                                   
48   return region_array()->steal(queue_num, region);                                                                         
49 }                                                                                                                          
50 
51 inline void ParCompactionManager::push(oop obj) {                                                                          
52   _marking_stack.push(obj);                                                                                                
53 }                                                                                                                          
54 
55 void ParCompactionManager::push_objarray(oop obj, size_t index)                                                            
56 {                                                                                                                          
57   ObjArrayTask task(obj, index);                                                                                           

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 #ifndef SHARE_VM_GC_PARALLEL_PSCOMPACTIONMANAGER_INLINE_HPP
25 #define SHARE_VM_GC_PARALLEL_PSCOMPACTIONMANAGER_INLINE_HPP
26 
27 #include "classfile/javaClasses.inline.hpp"
28 #include "gc/parallel/parMarkBitMap.hpp"
29 #include "gc/parallel/psCompactionManager.hpp"
30 #include "gc/parallel/psParallelCompact.inline.hpp"
31 #include "gc/shared/taskqueue.inline.hpp"
32 #include "oops/access.inline.hpp"
33 #include "oops/arrayOop.inline.hpp"
34 #include "oops/compressedOops.inline.hpp"
35 #include "oops/objArrayOop.inline.hpp"
36 #include "oops/oop.inline.hpp"
37 #include "utilities/debug.hpp"
38 #include "utilities/globalDefinitions.hpp"
39 
40 class PCMarkAndPushClosure: public OopClosure {
41 private:
42   ParCompactionManager* _compaction_manager;
43 public:
44   PCMarkAndPushClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }
45 
46   template <typename T> void do_oop_nv(T* p)      { _compaction_manager->mark_and_push(p); }
47   virtual void do_oop(oop* p)                     { do_oop_nv(p); }
48   virtual void do_oop(narrowOop* p)               { do_oop_nv(p); }
49 
50   // This closure provides its own oop verification code.
51   debug_only(virtual bool should_verify_oops()    { return false; })
52 };
53 
54 class PCIterateMarkAndPushClosure: public MetadataVisitingOopIterateClosure {
55 private:
56   ParCompactionManager* _compaction_manager;
57 public:
58   PCIterateMarkAndPushClosure(ParCompactionManager* cm, ReferenceProcessor* rp) : MetadataVisitingOopIterateClosure(rp), _c
59 
60   template <typename T> void do_oop_nv(T* p)      { _compaction_manager->mark_and_push(p); }
61   virtual void do_oop(oop* p)                     { do_oop_nv(p); }
62   virtual void do_oop(narrowOop* p)               { do_oop_nv(p); }
63 
64   void do_klass_nv(Klass* k)                      { _compaction_manager->follow_klass(k); }
65   void do_cld_nv(ClassLoaderData* cld)            { _compaction_manager->follow_class_loader(cld); }
66 
67   // This closure provides its own oop verification code.
68   debug_only(virtual bool should_verify_oops()    { return false; })
69 };
70 
71 inline bool ParCompactionManager::steal(int queue_num, oop& t) {
72   return stack_array()->steal(queue_num, t);
73 }
74 
75 inline bool ParCompactionManager::steal_objarray(int queue_num, ObjArrayTask& t) {
76   return _objarray_queues->steal(queue_num, t);
77 }
78 
79 inline bool ParCompactionManager::steal(int queue_num, size_t& region) {
80   return region_array()->steal(queue_num, region);
81 }
82 
83 inline void ParCompactionManager::push(oop obj) {
84   _marking_stack.push(obj);
85 }
86 
87 void ParCompactionManager::push_objarray(oop obj, size_t index)
88 {
89   ObjArrayTask task(obj, index);

66   ParallelCompactData::RegionData* const region_ptr = sd.region(index);                                                    
67   assert(region_ptr->claimed(), "must be claimed");                                                                        
68   assert(region_ptr->_pushed++ == 0, "should only be pushed once");                                                        
69 #endif                                                                                                                     
70   region_stack()->push(index);                                                                                             
71 }                                                                                                                          
72 
73 template <typename T>                                                                                                      
74 inline void ParCompactionManager::mark_and_push(T* p) {                                                                    
75   T heap_oop = RawAccess<>::oop_load(p);                                                                                   
76   if (!CompressedOops::is_null(heap_oop)) {                                                                                
77     oop obj = CompressedOops::decode_not_null(heap_oop);                                                                   
78     assert(ParallelScavengeHeap::heap()->is_in(obj), "should be in heap");                                                 
79 
80     if (mark_bitmap()->is_unmarked(obj) && PSParallelCompact::mark_obj(obj)) {                                             
81       push(obj);                                                                                                           
82     }                                                                                                                      
83   }                                                                                                                        
84 }                                                                                                                          
85 
86 template <typename T>                                                                                                      
87 inline void ParCompactionManager::MarkAndPushClosure::do_oop_work(T* p) {                                                  
88   _compaction_manager->mark_and_push(p);                                                                                   
89 }                                                                                                                          
90                                                                                                                            
91 inline void ParCompactionManager::MarkAndPushClosure::do_oop(oop* p)       { do_oop_work(p); }                             
92 inline void ParCompactionManager::MarkAndPushClosure::do_oop(narrowOop* p) { do_oop_work(p); }                             
93                                                                                                                            
94 inline void ParCompactionManager::follow_klass(Klass* klass) {                                                             
95   oop holder = klass->klass_holder();                                                                                      
96   mark_and_push(&holder);                                                                                                  
97 }                                                                                                                          
98 
99 inline void ParCompactionManager::FollowStackClosure::do_void() {                                                          
100   _compaction_manager->follow_marking_stacks();                                                                            
101 }                                                                                                                          
102 
103 inline void ParCompactionManager::follow_class_loader(ClassLoaderData* cld) {                                              
104   MarkAndPushClosure mark_and_push_closure(this);                                                                          
105                                                                                                                            
106   cld->oops_do(&mark_and_push_closure, true);                                                                              
107 }                                                                                                                          
108                                                                                                                            
109 inline void ParCompactionManager::follow_contents(oop obj) {                                                               
110   assert(PSParallelCompact::mark_bitmap()->is_marked(obj), "should be marked");                                            
111   obj->pc_follow_contents(this);                                                                                           
112 }                                                                                                                          
113                                                                                                                            
114 template <class T>                                                                                                         
115 inline void oop_pc_follow_contents_specialized(objArrayOop obj, int index, ParCompactionManager* cm) {                     
116   const size_t len = size_t(obj->length());                                                                                
117   const size_t beg_index = size_t(index);                                                                                  
118   assert(beg_index < len || len == 0, "index too large");                                                                  
119 
120   const size_t stride = MIN2(len - beg_index, (size_t)ObjArrayMarkingStride);                                              
121   const size_t end_index = beg_index + stride;                                                                             
122   T* const base = (T*)obj->base_raw();                                                                                     
123   T* const beg = base + beg_index;                                                                                         
124   T* const end = base + end_index;                                                                                         
125 
126   if (end_index < len) {                                                                                                   
127     cm->push_objarray(obj, end_index); // Push the continuation.                                                           
128   }                                                                                                                        
129 
130   // Push the non-NULL elements of the next stride on the marking stack.                                                   
131   for (T* e = beg; e < end; e++) {                                                                                         
132     cm->mark_and_push<T>(e);                                                                                               
133   }                                                                                                                        
134 }                                                                                                                          
135 
136 inline void ParCompactionManager::follow_contents(objArrayOop obj, int index) {                                            
137   if (UseCompressedOops) {                                                                                                 
138     oop_pc_follow_contents_specialized<narrowOop>(obj, index, this);                                                       
139   } else {                                                                                                                 
140     oop_pc_follow_contents_specialized<oop>(obj, index, this);                                                             
141   }                                                                                                                        
142 }                                                                                                                          
143 
144 inline void ParCompactionManager::update_contents(oop obj) {                                                               
145   obj->pc_update_contents(this);                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
                                                                                                                           
146 }                                                                                                                          
147 
148 #endif // SHARE_VM_GC_PARALLEL_PSCOMPACTIONMANAGER_INLINE_HPP                                                              

98   ParallelCompactData::RegionData* const region_ptr = sd.region(index);
99   assert(region_ptr->claimed(), "must be claimed");
100   assert(region_ptr->_pushed++ == 0, "should only be pushed once");
101 #endif
102   region_stack()->push(index);
103 }
104 
105 template <typename T>
106 inline void ParCompactionManager::mark_and_push(T* p) {
107   T heap_oop = RawAccess<>::oop_load(p);
108   if (!CompressedOops::is_null(heap_oop)) {
109     oop obj = CompressedOops::decode_not_null(heap_oop);
110     assert(ParallelScavengeHeap::heap()->is_in(obj), "should be in heap");
111 
112     if (mark_bitmap()->is_unmarked(obj) && PSParallelCompact::mark_obj(obj)) {
113       push(obj);
114     }
115   }
116 }
117 








118 inline void ParCompactionManager::follow_klass(Klass* klass) {
119   oop holder = klass->klass_holder();
120   mark_and_push(&holder);
121 }
122 
123 inline void ParCompactionManager::FollowStackClosure::do_void() {
124   _compaction_manager->follow_marking_stacks();
125 }
126 
127 template <typename T>
128 inline void follow_array_specialized(objArrayOop obj, int index, ParCompactionManager* cm) {











129   const size_t len = size_t(obj->length());
130   const size_t beg_index = size_t(index);
131   assert(beg_index < len || len == 0, "index too large");
132 
133   const size_t stride = MIN2(len - beg_index, (size_t)ObjArrayMarkingStride);
134   const size_t end_index = beg_index + stride;
135   T* const base = (T*)obj->base_raw();
136   T* const beg = base + beg_index;
137   T* const end = base + end_index;
138 
139   if (end_index < len) {
140     cm->push_objarray(obj, end_index); // Push the continuation.
141   }
142 
143   // Push the non-NULL elements of the next stride on the marking stack.
144   for (T* e = beg; e < end; e++) {
145     cm->mark_and_push<T>(e);
146   }
147 }
148 
149 inline void ParCompactionManager::follow_array(objArrayOop obj, int index) {
150   if (UseCompressedOops) {
151     follow_array_specialized<narrowOop>(obj, index, this);
152   } else {
153     follow_array_specialized<oop>(obj, index, this);
154   }
155 }
156 
157 inline void ParCompactionManager::update_contents(oop obj) {
158   obj->pc_update_contents(this);
159 }
160 
161 inline void ParCompactionManager::follow_class_loader(ClassLoaderData* cld) {
162   PCMarkAndPushClosure mark_and_push_closure(this);
163   cld->oops_do(&mark_and_push_closure, true);
164 }
165 
166 inline void ParCompactionManager::follow_contents(oop obj) {
167   assert(PSParallelCompact::mark_bitmap()->is_marked(obj), "should be marked");
168   if (obj->is_objArray()) {
169     follow_array(objArrayOop(obj), 0);
170   } else {
171     PCIterateMarkAndPushClosure cl(this, PSParallelCompact::ref_processor());
172     obj->oop_iterate(&cl);
173   }
174 }
175 
176 #endif // SHARE_VM_GC_PARALLEL_PSCOMPACTIONMANAGER_INLINE_HPP
< prev index next >