< prev index next >

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

BarrierSetC2

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 BarrierSetAssembler;                                                                                                           
36 class BarrierSetC1;                                                                                                                  
                                                                                                                                     
37 class JavaThread;                                                                                                                    
38 
39 // This class provides the interface between a barrier implementation and                                                            
40 // the rest of the system.                                                                                                           
41 
42 class BarrierSet: public CHeapObj<mtGC> {                                                                                            
43   friend class VMStructs;                                                                                                            
44 
45   static BarrierSet* _barrier_set;                                                                                                   
46 
47 public:                                                                                                                              
48   enum Name {                                                                                                                        
49 #define BARRIER_SET_DECLARE_BS_ENUM(bs_name) bs_name ,                                                                               
50     FOR_EACH_BARRIER_SET_DO(BARRIER_SET_DECLARE_BS_ENUM)                                                                             
51 #undef BARRIER_SET_DECLARE_BS_ENUM                                                                                                   
52     UnknownBS                                                                                                                        
53   };                                                                                                                                 
54 
55 protected:                                                                                                                           
56   // Fake RTTI support.  For a derived class T to participate                                                                        
57   // - T must have a corresponding Name entry.                                                                                       
58   // - GetName<T> must be specialized to return the corresponding Name                                                               
59   //   entry.                                                                                                                        
60   // - If T is a base class, the constructor must have a FakeRtti                                                                    
61   //   parameter and pass it up to its base class, with the tag set                                                                  
62   //   augmented with the corresponding Name entry.                                                                                  
63   // - If T is a concrete class, the constructor must create a                                                                       
64   //   FakeRtti object whose tag set includes the corresponding Name                                                                 
65   //   entry, and pass it up to its base class.                                                                                      
66   typedef FakeRttiSupport<BarrierSet, Name> FakeRtti;                                                                                
67 
68 private:                                                                                                                             
69   FakeRtti _fake_rtti;                                                                                                               
70   BarrierSetAssembler* _barrier_set_assembler;                                                                                       
71   BarrierSetC1* _barrier_set_c1;                                                                                                     
                                                                                                                                     
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,                                                                             
93              BarrierSetC1* barrier_set_c1,                                                                                           
                                                                                                                                     
94              const FakeRtti& fake_rtti) :                                                                                            
95     _fake_rtti(fake_rtti),                                                                                                           
96     _barrier_set_assembler(barrier_set_assembler),                                                                                   
97     _barrier_set_c1(barrier_set_c1) {}                                                                                               
                                                                                                                                     
98   ~BarrierSet() { }                                                                                                                  
99 
100   template <class BarrierSetAssemblerT>                                                                                              
101   BarrierSetAssembler* make_barrier_set_assembler() {                                                                                
102     return NOT_ZERO(new BarrierSetAssemblerT()) ZERO_ONLY(NULL);                                                                     
103   }                                                                                                                                  
104 
105   template <class BarrierSetC1T>                                                                                                     
106   BarrierSetC1* make_barrier_set_c1() {                                                                                              
107     return COMPILER1_PRESENT(new BarrierSetC1T()) NOT_COMPILER1(NULL);                                                               
108   }                                                                                                                                  
109 
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
110 public:                                                                                                                              
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_create(Thread* thread) {}                                                                                   
118   virtual void on_thread_destroy(Thread* thread) {}                                                                                  
119   virtual void on_thread_attach(JavaThread* thread) {}                                                                               
120   virtual void on_thread_detach(JavaThread* thread) {}                                                                               
121   virtual void make_parsable(JavaThread* thread) {}                                                                                  
122 
123 public:                                                                                                                              
124   // Print a description of the memory for the barrier set                                                                           
125   virtual void print_on(outputStream* st) const = 0;                                                                                 
126 
127   static BarrierSet* barrier_set() { return _barrier_set; }                                                                          
128   static void set_barrier_set(BarrierSet* barrier_set);                                                                              
129 
130   BarrierSetAssembler* barrier_set_assembler() {                                                                                     
131     assert(_barrier_set_assembler != NULL, "should be set");                                                                         
132     return _barrier_set_assembler;                                                                                                   
133   }                                                                                                                                  
134 
135   BarrierSetC1* barrier_set_c1() {                                                                                                   
136     assert(_barrier_set_c1 != NULL, "should be set");                                                                                
137     return _barrier_set_c1;                                                                                                          
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
                                                                                                                                     
138   }                                                                                                                                  
139 
140   // The AccessBarrier of a BarrierSet subclass is called by the Access API                                                          
141   // (cf. oops/access.hpp) to perform decorated accesses. GC implementations                                                         
142   // may override these default access operations by declaring an                                                                    
143   // AccessBarrier class in its BarrierSet. Its accessors will then be                                                               
144   // automatically resolved at runtime.                                                                                              
145   //                                                                                                                                 
146   // In order to register a new FooBarrierSet::AccessBarrier with the Access API,                                                    
147   // the following steps should be taken:                                                                                            
148   // 1) Provide an enum "name" for the BarrierSet in barrierSetConfig.hpp                                                            
149   // 2) Make sure the barrier set headers are included from barrierSetConfig.inline.hpp                                              
150   // 3) Provide specializations for BarrierSet::GetName and BarrierSet::GetType.                                                     
151   template <DecoratorSet decorators, typename BarrierSetT>                                                                           
152   class AccessBarrier: protected RawAccessBarrier<decorators> {                                                                      
153   private:                                                                                                                           
154     typedef RawAccessBarrier<decorators> Raw;                                                                                        
155 
156   public:                                                                                                                            

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 BarrierSetAssembler;
36 class BarrierSetC1;
37 class BarrierSetC2;
38 class JavaThread;
39 
40 // This class provides the interface between a barrier implementation and
41 // the rest of the system.
42 
43 class BarrierSet: public CHeapObj<mtGC> {
44   friend class VMStructs;
45 
46   static BarrierSet* _barrier_set;
47 
48 public:
49   enum Name {
50 #define BARRIER_SET_DECLARE_BS_ENUM(bs_name) bs_name ,
51     FOR_EACH_BARRIER_SET_DO(BARRIER_SET_DECLARE_BS_ENUM)
52 #undef BARRIER_SET_DECLARE_BS_ENUM
53     UnknownBS
54   };
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   BarrierSetC1* _barrier_set_c1;
73   BarrierSetC2* _barrier_set_c2;
74 
75 public:
76   // Metafunction mapping a class derived from BarrierSet to the
77   // corresponding Name enum tag.
78   template<typename T> struct GetName;
79 
80   // Metafunction mapping a Name enum type to the corresponding
81   // lass derived from BarrierSet.
82   template<BarrierSet::Name T> struct GetType;
83 
84   // Note: This is not presently the Name corresponding to the
85   // concrete class of this object.
86   BarrierSet::Name kind() const { return _fake_rtti.concrete_tag(); }
87 
88   // Test whether this object is of the type corresponding to bsn.
89   bool is_a(BarrierSet::Name bsn) const { return _fake_rtti.has_tag(bsn); }
90 
91   // End of fake RTTI support.
92 
93 protected:
94   BarrierSet(BarrierSetAssembler* barrier_set_assembler,
95              BarrierSetC1* barrier_set_c1,
96              BarrierSetC2* barrier_set_c2,
97              const FakeRtti& fake_rtti) :
98     _fake_rtti(fake_rtti),
99     _barrier_set_assembler(barrier_set_assembler),
100     _barrier_set_c1(barrier_set_c1),
101     _barrier_set_c2(barrier_set_c2) {}
102   ~BarrierSet() { }
103 
104   template <class BarrierSetAssemblerT>
105   BarrierSetAssembler* make_barrier_set_assembler() {
106     return NOT_ZERO(new BarrierSetAssemblerT()) ZERO_ONLY(NULL);
107   }
108 
109   template <class BarrierSetC1T>
110   BarrierSetC1* make_barrier_set_c1() {
111     return COMPILER1_PRESENT(new BarrierSetC1T()) NOT_COMPILER1(NULL);
112   }
113 
114   template <class BarrierSetC2T>
115   BarrierSetC2* make_barrier_set_c2() {
116     return COMPILER2_PRESENT(new BarrierSetC2T()) NOT_COMPILER2(NULL);
117   }
118 
119 public:
120   // Support for optimizing compilers to call the barrier set on slow path allocations
121   // that did not enter a TLAB. Used for e.g. ReduceInitialCardMarks.
122   // The allocation is safe to use iff it returns true. If not, the slow-path allocation
123   // is redone until it succeeds. This can e.g. prevent allocations from the slow path
124   // to be in old.
125   virtual void on_slowpath_allocation_exit(JavaThread* thread, oop new_obj) {}
126   virtual void on_thread_create(Thread* thread) {}
127   virtual void on_thread_destroy(Thread* thread) {}
128   virtual void on_thread_attach(JavaThread* thread) {}
129   virtual void on_thread_detach(JavaThread* thread) {}
130   virtual void make_parsable(JavaThread* thread) {}
131 
132 public:
133   // Print a description of the memory for the barrier set
134   virtual void print_on(outputStream* st) const = 0;
135 
136   static BarrierSet* barrier_set() { return _barrier_set; }
137   static void set_barrier_set(BarrierSet* barrier_set);
138 
139   BarrierSetAssembler* barrier_set_assembler() {
140     assert(_barrier_set_assembler != NULL, "should be set");
141     return _barrier_set_assembler;
142   }
143 
144   BarrierSetC1* barrier_set_c1() {
145     assert(_barrier_set_c1 != NULL, "should be set");
146     return _barrier_set_c1;
147   }
148 
149   BarrierSetC2* barrier_set_c2() {
150     assert(_barrier_set_c2 != NULL, "should be set");
151     return _barrier_set_c2;
152   }
153 
154   // The AccessBarrier of a BarrierSet subclass is called by the Access API
155   // (cf. oops/access.hpp) to perform decorated accesses. GC implementations
156   // may override these default access operations by declaring an
157   // AccessBarrier class in its BarrierSet. Its accessors will then be
158   // automatically resolved at runtime.
159   //
160   // In order to register a new FooBarrierSet::AccessBarrier with the Access API,
161   // the following steps should be taken:
162   // 1) Provide an enum "name" for the BarrierSet in barrierSetConfig.hpp
163   // 2) Make sure the barrier set headers are included from barrierSetConfig.inline.hpp
164   // 3) Provide specializations for BarrierSet::GetName and BarrierSet::GetType.
165   template <DecoratorSet decorators, typename BarrierSetT>
166   class AccessBarrier: protected RawAccessBarrier<decorators> {
167   private:
168     typedef RawAccessBarrier<decorators> Raw;
169 
170   public:
< prev index next >