25 #ifndef SHARE_VM_MEMORY_BARRIERSET_HPP |
25 #ifndef SHARE_VM_MEMORY_BARRIERSET_HPP |
26 #define SHARE_VM_MEMORY_BARRIERSET_HPP |
26 #define SHARE_VM_MEMORY_BARRIERSET_HPP |
27 |
27 |
28 #include "memory/memRegion.hpp" |
28 #include "memory/memRegion.hpp" |
29 #include "oops/oopsHierarchy.hpp" |
29 #include "oops/oopsHierarchy.hpp" |
|
30 #include "utilities/fakeRttiSupport.hpp" |
30 |
31 |
31 // This class provides the interface between a barrier implementation and |
32 // This class provides the interface between a barrier implementation and |
32 // the rest of the system. |
33 // the rest of the system. |
33 |
34 |
34 class BarrierSet: public CHeapObj<mtGC> { |
35 class BarrierSet: public CHeapObj<mtGC> { |
35 friend class VMStructs; |
36 friend class VMStructs; |
36 public: |
37 public: |
37 enum Name { |
38 // Fake RTTI support. For a derived class T to participate |
38 ModRef, |
39 // - T must have a corresponding Name entry. |
39 CardTableModRef, |
40 // - GetName<T> must be specialized to return the corresponding Name |
40 CardTableExtension, |
41 // entry. |
41 G1SATBCT, |
42 // - If T is a base class, the constructor must have a FakeRtti |
42 G1SATBCTLogging |
43 // parameter and pass it up to its base class, with the tag set |
|
44 // augmented with the corresponding Name entry. |
|
45 // - If T is a concrete class, the constructor must create a |
|
46 // FakeRtti object whose tag set includes the corresponding Name |
|
47 // entry, and pass it up to its base class. |
|
48 |
|
49 enum Name { // associated class |
|
50 ModRef, // ModRefBarrierSet |
|
51 CardTableModRef, // CardTableModRefBS |
|
52 CardTableForRS, // CardTableModRefBSForCTRS |
|
53 CardTableExtension, // CardTableExtension |
|
54 G1SATBCT, // G1SATBCardTableModRefBS |
|
55 G1SATBCTLogging // G1SATBCardTableLoggingModRefBS |
43 }; |
56 }; |
44 |
57 |
|
58 protected: |
|
59 typedef FakeRttiSupport<BarrierSet, Name> FakeRtti; |
|
60 |
|
61 private: |
|
62 FakeRtti _fake_rtti; |
|
63 |
|
64 // Metafunction mapping a class derived from BarrierSet to the |
|
65 // corresponding Name enum tag. |
|
66 template<typename T> struct GetName; |
|
67 |
|
68 // Downcast argument to a derived barrier set type. |
|
69 // The cast is checked in a debug build. |
|
70 // T must have a specialization for BarrierSet::GetName<T>. |
|
71 template<typename T> |
|
72 friend T* barrier_set_cast(BarrierSet* bs) { |
|
73 assert(bs->is_a(BarrierSet::GetName<T>::value), "wrong type of barrier set"); |
|
74 return static_cast<T*>(bs); |
|
75 } |
|
76 |
|
77 public: |
|
78 // Note: This is not presently the Name corresponding to the |
|
79 // concrete class of this object. |
|
80 BarrierSet::Name kind() const { return _fake_rtti.concrete_tag(); } |
|
81 |
|
82 // Test whether this object is of the type corresponding to bsn. |
|
83 bool is_a(BarrierSet::Name bsn) const { return _fake_rtti.has_tag(bsn); } |
|
84 |
|
85 // End of fake RTTI support. |
|
86 |
|
87 public: |
45 enum Flags { |
88 enum Flags { |
46 None = 0, |
89 None = 0, |
47 TargetUninitialized = 1 |
90 TargetUninitialized = 1 |
48 }; |
91 }; |
|
92 |
49 protected: |
93 protected: |
50 // Some barrier sets create tables whose elements correspond to parts of |
94 // Some barrier sets create tables whose elements correspond to parts of |
51 // the heap; the CardTableModRefBS is an example. Such barrier sets will |
95 // the heap; the CardTableModRefBS is an example. Such barrier sets will |
52 // normally reserve space for such tables, and commit parts of the table |
96 // normally reserve space for such tables, and commit parts of the table |
53 // "covering" parts of the heap that are committed. At most one covered |
97 // "covering" parts of the heap that are committed. At most one covered |
54 // region per generation is needed. |
98 // region per generation is needed. |
55 static const int _max_covered_regions = 2; |
99 static const int _max_covered_regions = 2; |
56 Name _kind; |
100 |
57 |
101 BarrierSet(const FakeRtti& fake_rtti) : _fake_rtti(fake_rtti) { } |
58 BarrierSet(Name kind) : _kind(kind) { } |
|
59 ~BarrierSet() { } |
102 ~BarrierSet() { } |
60 |
103 |
61 public: |
104 public: |
62 |
|
63 // To get around prohibition on RTTI. |
|
64 BarrierSet::Name kind() { return _kind; } |
|
65 virtual bool is_a(BarrierSet::Name bsn) = 0; |
|
66 |
105 |
67 // These operations indicate what kind of barriers the BarrierSet has. |
106 // These operations indicate what kind of barriers the BarrierSet has. |
68 virtual bool has_read_ref_barrier() = 0; |
107 virtual bool has_read_ref_barrier() = 0; |
69 virtual bool has_read_prim_barrier() = 0; |
108 virtual bool has_read_prim_barrier() = 0; |
70 virtual bool has_write_ref_barrier() = 0; |
109 virtual bool has_write_ref_barrier() = 0; |