< prev index next >

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

8198949_arraycopy

rename things

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_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 
54 protected:                                                                                                                           
55   // Fake RTTI support.  For a derived class T to participate                                                                        
56   // - T must have a corresponding Name entry.                                                                                       
57   // - GetName<T> must be specialized to return the corresponding Name                                                               
58   //   entry.                                                                                                                        
59   // - If T is a base class, the constructor must have a FakeRtti                                                                    
60   //   parameter and pass it up to its base class, with the tag set                                                                  
61   //   augmented with the corresponding Name entry.                                                                                  
62   // - If T is a concrete class, the constructor must create a                                                                       
63   //   FakeRtti object whose tag set includes the corresponding Name                                                                 
64   //   entry, and pass it up to its base class.                                                                                      
65   typedef FakeRttiSupport<BarrierSet, Name> FakeRtti;                                                                                
66 
67 private:                                                                                                                             
68   FakeRtti _fake_rtti;                                                                                                               
                                                                                                                                     
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                                                                    

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_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 #include "utilities/macros.hpp"
34 
35 class JavaThread;
36 class BarrierSetAssembler;
37 
38 // This class provides the interface between a barrier implementation and
39 // the rest of the system.
40 
41 class BarrierSet: public CHeapObj<mtGC> {
42   friend class VMStructs;
43 
44   static BarrierSet* _bs;
45 
46 public:
47   enum Name {
48 #define BARRIER_SET_DECLARE_BS_ENUM(bs_name) bs_name ,
49     FOR_EACH_BARRIER_SET_DO(BARRIER_SET_DECLARE_BS_ENUM)
50 #undef BARRIER_SET_DECLARE_BS_ENUM
51     UnknownBS
52   };
53 
54   static BarrierSet* barrier_set() { return _bs; }
55 
56 protected:
57   // Fake RTTI support.  For a derived class T to participate
58   // - T must have a corresponding Name entry.
59   // - GetName<T> must be specialized to return the corresponding Name
60   //   entry.
61   // - If T is a base class, the constructor must have a FakeRtti
62   //   parameter and pass it up to its base class, with the tag set
63   //   augmented with the corresponding Name entry.
64   // - If T is a concrete class, the constructor must create a
65   //   FakeRtti object whose tag set includes the corresponding Name
66   //   entry, and pass it up to its base class.
67   typedef FakeRttiSupport<BarrierSet, Name> FakeRtti;
68 
69 private:
70   FakeRtti _fake_rtti;
71   BarrierSetAssembler* _barrier_set_assembler;
72 
73 public:
74   // Metafunction mapping a class derived from BarrierSet to the
75   // corresponding Name enum tag.
76   template<typename T> struct GetName;
77 
78   // Metafunction mapping a Name enum type to the corresponding
79   // lass derived from BarrierSet.
80   template<BarrierSet::Name T> struct GetType;
81 
82   // Note: This is not presently the Name corresponding to the
83   // concrete class of this object.
84   BarrierSet::Name kind() const { return _fake_rtti.concrete_tag(); }
85 
86   // Test whether this object is of the type corresponding to bsn.
87   bool is_a(BarrierSet::Name bsn) const { return _fake_rtti.has_tag(bsn); }
88 
89   // End of fake RTTI support.
90 
91 protected:
92   BarrierSet(BarrierSetAssembler* barrier_set_assembler, const FakeRtti& fake_rtti) :
93     _fake_rtti(fake_rtti),
94     _barrier_set_assembler(barrier_set_assembler) { }
95   ~BarrierSet() { }
96 
97   template <class BarrierSetAssemblerT>
98   BarrierSetAssembler* make_barrier_set_assembler() {
99     return NOT_ZERO(new BarrierSetAssemblerT()) ZERO_ONLY(NULL);
100   }














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



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