< prev index next >

src/hotspot/share/gc/shared/barrierSet.hpp

8198949_arraycopy

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_SHARED_BARRIERSET_HPP                                                                                            
25 #define SHARE_VM_GC_SHARED_BARRIERSET_HPP                                                                                            
26 
27 #include "gc/shared/barrierSetConfig.hpp"                                                                                            
28 #include "memory/memRegion.hpp"                                                                                                      
29 #include "oops/access.hpp"                                                                                                           
30 #include "oops/accessBackend.hpp"                                                                                                    
31 #include "oops/oopsHierarchy.hpp"                                                                                                    
32 #include "utilities/fakeRttiSupport.hpp"                                                                                             
33 
34 class JavaThread;                                                                                                                    
                                                                                                                                     
35 
36 // This class provides the interface between a barrier implementation and                                                            
37 // the rest of the system.                                                                                                           
38 
39 class BarrierSet: public CHeapObj<mtGC> {                                                                                            
40   friend class VMStructs;                                                                                                            
41 
42   static BarrierSet* _bs;                                                                                                            
43 
44 public:                                                                                                                              
45   enum Name {                                                                                                                        
46 #define BARRIER_SET_DECLARE_BS_ENUM(bs_name) bs_name ,                                                                               
47     FOR_EACH_BARRIER_SET_DO(BARRIER_SET_DECLARE_BS_ENUM)                                                                             
48 #undef BARRIER_SET_DECLARE_BS_ENUM                                                                                                   
49     UnknownBS                                                                                                                        
50   };                                                                                                                                 
51 
52   static BarrierSet* barrier_set() { return _bs; }                                                                                   
53 

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_SHARED_BARRIERSET_HPP
25 #define SHARE_VM_GC_SHARED_BARRIERSET_HPP
26 
27 #include "gc/shared/barrierSetConfig.hpp"
28 #include "memory/memRegion.hpp"
29 #include "oops/access.hpp"
30 #include "oops/accessBackend.hpp"
31 #include "oops/oopsHierarchy.hpp"
32 #include "utilities/fakeRttiSupport.hpp"
33 
34 class JavaThread;
35 class BarrierSetCodeGen;
36 
37 // This class provides the interface between a barrier implementation and
38 // the rest of the system.
39 
40 class BarrierSet: public CHeapObj<mtGC> {
41   friend class VMStructs;
42 
43   static BarrierSet* _bs;
44 
45 public:
46   enum Name {
47 #define BARRIER_SET_DECLARE_BS_ENUM(bs_name) bs_name ,
48     FOR_EACH_BARRIER_SET_DO(BARRIER_SET_DECLARE_BS_ENUM)
49 #undef BARRIER_SET_DECLARE_BS_ENUM
50     UnknownBS
51   };
52 
53   static BarrierSet* barrier_set() { return _bs; }
54 

69 
70 public:                                                                                                                              
71   // Metafunction mapping a class derived from BarrierSet to the                                                                     
72   // corresponding Name enum tag.                                                                                                    
73   template<typename T> struct GetName;                                                                                               
74 
75   // Metafunction mapping a Name enum type to the corresponding                                                                      
76   // lass derived from BarrierSet.                                                                                                   
77   template<BarrierSet::Name T> struct GetType;                                                                                       
78 
79   // Note: This is not presently the Name corresponding to the                                                                       
80   // concrete class of this object.                                                                                                  
81   BarrierSet::Name kind() const { return _fake_rtti.concrete_tag(); }                                                                
82 
83   // Test whether this object is of the type corresponding to bsn.                                                                   
84   bool is_a(BarrierSet::Name bsn) const { return _fake_rtti.has_tag(bsn); }                                                          
85 
86   // End of fake RTTI support.                                                                                                       
87 
88 protected:                                                                                                                           
89   BarrierSet(const FakeRtti& fake_rtti) : _fake_rtti(fake_rtti) { }                                                                  
90   ~BarrierSet() { }                                                                                                                  
                                                                                                                                     
                                                                                                                                     
91 
92 public:                                                                                                                              
93   // Operations on arrays, or general regions (e.g., for "clone") may be                                                             
94   // optimized by some barriers.                                                                                                     
95                                                                                                                                      
96   // Below length is the # array elements being written                                                                              
97   virtual void write_ref_array_pre(oop* dst, int length,                                                                             
98                                    bool dest_uninitialized = false) {}                                                               
99   virtual void write_ref_array_pre(narrowOop* dst, int length,                                                                       
100                                    bool dest_uninitialized = false) {}                                                               
101   // Below count is the # array elements being written, starting                                                                     
102   // at the address "start", which may not necessarily be HeapWord-aligned                                                           
103   inline void write_ref_array(HeapWord* start, size_t count);                                                                        
104                                                                                                                                      
105   // Static versions, suitable for calling from generated code;                                                                      
106   // count is # array elements being written, starting with "start",                                                                 
107   // which may not necessarily be HeapWord-aligned.                                                                                  
108   static void static_write_ref_array_pre(HeapWord* start, size_t count);                                                             
109   static void static_write_ref_array_post(HeapWord* start, size_t count);                                                            
110                                                                                                                                      
111   // Support for optimizing compilers to call the barrier set on slow path allocations                                               
112   // that did not enter a TLAB. Used for e.g. ReduceInitialCardMarks.                                                                
113   // The allocation is safe to use iff it returns true. If not, the slow-path allocation                                             
114   // is redone until it succeeds. This can e.g. prevent allocations from the slow path                                               
115   // to be in old.                                                                                                                   
116   virtual void on_slowpath_allocation_exit(JavaThread* thread, oop new_obj) {}                                                       
117   virtual void on_thread_attach(JavaThread* thread) {}                                                                               
118   virtual void on_thread_detach(JavaThread* thread) {}                                                                               
119   virtual void make_parsable(JavaThread* thread) {}                                                                                  
120 
121 protected:                                                                                                                           
122   virtual void write_ref_array_work(MemRegion mr) = 0;                                                                               
123                                                                                                                                      
124 public:                                                                                                                              
125   // Print a description of the memory for the barrier set                                                                           
126   virtual void print_on(outputStream* st) const = 0;                                                                                 
127 
128   static void set_bs(BarrierSet* bs) { _bs = bs; }                                                                                   
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
129 
130   // The AccessBarrier of a BarrierSet subclass is called by the Access API                                                          
131   // (cf. oops/access.hpp) to perform decorated accesses. GC implementations                                                         
132   // may override these default access operations by declaring an                                                                    
133   // AccessBarrier class in its BarrierSet. Its accessors will then be                                                               
134   // automatically resolved at runtime.                                                                                              
135   //                                                                                                                                 
136   // In order to register a new FooBarrierSet::AccessBarrier with the Access API,                                                    
137   // the following steps should be taken:                                                                                            
138   // 1) Provide an enum "name" for the BarrierSet in barrierSetConfig.hpp                                                            
139   // 2) Make sure the barrier set headers are included from barrierSetConfig.inline.hpp                                              
140   // 3) Provide specializations for BarrierSet::GetName and BarrierSet::GetType.                                                     
141   template <DecoratorSet decorators, typename BarrierSetT>                                                                           
142   class AccessBarrier: protected RawAccessBarrier<decorators> {                                                                      
143   private:                                                                                                                           
144     typedef RawAccessBarrier<decorators> Raw;                                                                                        
145 
146   public:                                                                                                                            
147     // Primitive heap accesses. These accessors get resolved when                                                                    

70 
71 public:
72   // Metafunction mapping a class derived from BarrierSet to the
73   // corresponding Name enum tag.
74   template<typename T> struct GetName;
75 
76   // Metafunction mapping a Name enum type to the corresponding
77   // lass derived from BarrierSet.
78   template<BarrierSet::Name T> struct GetType;
79 
80   // Note: This is not presently the Name corresponding to the
81   // concrete class of this object.
82   BarrierSet::Name kind() const { return _fake_rtti.concrete_tag(); }
83 
84   // Test whether this object is of the type corresponding to bsn.
85   bool is_a(BarrierSet::Name bsn) const { return _fake_rtti.has_tag(bsn); }
86 
87   // End of fake RTTI support.
88 
89 protected:
90   BarrierSet(const FakeRtti& fake_rtti) : _fake_rtti(fake_rtti), _code_gen(NULL) { }
91   ~BarrierSet() { }
92   BarrierSetCodeGen* _code_gen;
93   virtual BarrierSetCodeGen* make_code_gen() = 0;
94 
95 public:


















96   // Support for optimizing compilers to call the barrier set on slow path allocations
97   // that did not enter a TLAB. Used for e.g. ReduceInitialCardMarks.
98   // The allocation is safe to use iff it returns true. If not, the slow-path allocation
99   // is redone until it succeeds. This can e.g. prevent allocations from the slow path
100   // to be in old.
101   virtual void on_slowpath_allocation_exit(JavaThread* thread, oop new_obj) {}
102   virtual void on_thread_attach(JavaThread* thread) {}
103   virtual void on_thread_detach(JavaThread* thread) {}
104   virtual void make_parsable(JavaThread* thread) {}
105 



106 public:
107   // Print a description of the memory for the barrier set
108   virtual void print_on(outputStream* st) const = 0;
109 
110   static void set_bs(BarrierSet* bs) { _bs = bs; }
111 
112   virtual void initialize();
113 
114   BarrierSetCodeGen* code_gen() {
115     assert(_code_gen != NULL, "should be set");
116     return _code_gen;
117   }
118 
119   // The AccessBarrier of a BarrierSet subclass is called by the Access API
120   // (cf. oops/access.hpp) to perform decorated accesses. GC implementations
121   // may override these default access operations by declaring an
122   // AccessBarrier class in its BarrierSet. Its accessors will then be
123   // automatically resolved at runtime.
124   //
125   // In order to register a new FooBarrierSet::AccessBarrier with the Access API,
126   // the following steps should be taken:
127   // 1) Provide an enum "name" for the BarrierSet in barrierSetConfig.hpp
128   // 2) Make sure the barrier set headers are included from barrierSetConfig.inline.hpp
129   // 3) Provide specializations for BarrierSet::GetName and BarrierSet::GetType.
130   template <DecoratorSet decorators, typename BarrierSetT>
131   class AccessBarrier: protected RawAccessBarrier<decorators> {
132   private:
133     typedef RawAccessBarrier<decorators> Raw;
134 
135   public:
136     // Primitive heap accesses. These accessors get resolved when
< prev index next >