Mercurial > hg > truffle
comparison src/share/vm/gc_implementation/g1/heapRegionSets.cpp @ 17736:58fc1b1523dc
8034079: G1: Refactor the HeapRegionSet hierarchy
Reviewed-by: tschatzl, pliden
author | brutisso |
---|---|
date | Fri, 14 Mar 2014 10:15:46 +0100 |
parents | 8aae2050e83e |
children |
comparison
equal
deleted
inserted
replaced
17735:8f28240318a2 | 17736:58fc1b1523dc |
---|---|
22 * | 22 * |
23 */ | 23 */ |
24 | 24 |
25 #include "precompiled.hpp" | 25 #include "precompiled.hpp" |
26 #include "gc_implementation/g1/heapRegionRemSet.hpp" | 26 #include "gc_implementation/g1/heapRegionRemSet.hpp" |
27 #include "gc_implementation/g1/heapRegionSets.hpp" | 27 #include "gc_implementation/g1/heapRegionSet.hpp" |
28 | 28 |
29 // Note on the check_mt_safety() methods below: | 29 // Note on the check_mt_safety() methods below: |
30 // | 30 // |
31 // Verification of the "master" heap region sets / lists that are | 31 // Verification of the "master" heap region sets / lists that are |
32 // maintained by G1CollectedHeap is always done during a STW pause and | 32 // maintained by G1CollectedHeap is always done during a STW pause and |
35 // important as it ensures that verification is done without | 35 // important as it ensures that verification is done without |
36 // concurrent updates taking place at the same time. It follows, that, | 36 // concurrent updates taking place at the same time. It follows, that, |
37 // for the "master" heap region sets / lists, the check_mt_safety() | 37 // for the "master" heap region sets / lists, the check_mt_safety() |
38 // method should include the VM thread / STW case. | 38 // method should include the VM thread / STW case. |
39 | 39 |
40 //////////////////// FreeRegionList //////////////////// | 40 void FreeRegionList::verify_list() { |
41 HeapRegion* curr = head(); | |
42 HeapRegion* prev1 = NULL; | |
43 HeapRegion* prev0 = NULL; | |
44 uint count = 0; | |
45 size_t capacity = 0; | |
46 while (curr != NULL) { | |
47 verify_region(curr); | |
41 | 48 |
42 const char* FreeRegionList::verify_region_extra(HeapRegion* hr) { | 49 count++; |
43 if (hr->is_young()) { | 50 guarantee(count < _unrealistically_long_length, |
44 return "the region should not be young"; | 51 hrs_err_msg("[%s] the calculated length: %u seems very long, is there maybe a cycle? curr: "PTR_FORMAT" prev0: "PTR_FORMAT" " "prev1: "PTR_FORMAT" length: %u", name(), count, curr, prev0, prev1, length())); |
52 | |
53 capacity += curr->capacity(); | |
54 | |
55 prev1 = prev0; | |
56 prev0 = curr; | |
57 curr = curr->next(); | |
45 } | 58 } |
46 // The superclass will check that the region is empty and | 59 |
47 // not humongous. | 60 guarantee(tail() == prev0, err_msg("Expected %s to end with %u but it ended with %u.", name(), tail()->hrs_index(), prev0->hrs_index())); |
48 return HeapRegionLinkedList::verify_region_extra(hr); | 61 |
62 guarantee(length() == count, err_msg("%s count mismatch. Expected %u, actual %u.", name(), length(), count)); | |
63 guarantee(total_capacity_bytes() == capacity, err_msg("%s capacity mismatch. Expected " SIZE_FORMAT ", actual " SIZE_FORMAT, | |
64 name(), total_capacity_bytes(), capacity)); | |
49 } | 65 } |
50 | 66 |
51 //////////////////// MasterFreeRegionList //////////////////// | 67 void MasterFreeRegionListMtSafeChecker::check() { |
52 | |
53 const char* MasterFreeRegionList::verify_region_extra(HeapRegion* hr) { | |
54 // We should reset the RSet for parallel iteration before we add it | |
55 // to the master free list so that it is ready when the region is | |
56 // re-allocated. | |
57 if (!hr->rem_set()->verify_ready_for_par_iteration()) { | |
58 return "the region's RSet should be ready for parallel iteration"; | |
59 } | |
60 return FreeRegionList::verify_region_extra(hr); | |
61 } | |
62 | |
63 bool MasterFreeRegionList::check_mt_safety() { | |
64 // Master Free List MT safety protocol: | 68 // Master Free List MT safety protocol: |
65 // (a) If we're at a safepoint, operations on the master free list | 69 // (a) If we're at a safepoint, operations on the master free list |
66 // should be invoked by either the VM thread (which will serialize | 70 // should be invoked by either the VM thread (which will serialize |
67 // them) or by the GC workers while holding the | 71 // them) or by the GC workers while holding the |
68 // FreeList_lock. | 72 // FreeList_lock. |
69 // (b) If we're not at a safepoint, operations on the master free | 73 // (b) If we're not at a safepoint, operations on the master free |
70 // list should be invoked while holding the Heap_lock. | 74 // list should be invoked while holding the Heap_lock. |
71 | 75 |
72 if (SafepointSynchronize::is_at_safepoint()) { | 76 if (SafepointSynchronize::is_at_safepoint()) { |
73 guarantee(Thread::current()->is_VM_thread() || | 77 guarantee(Thread::current()->is_VM_thread() || |
74 FreeList_lock->owned_by_self(), | 78 FreeList_lock->owned_by_self(), "master free list MT safety protocol at a safepoint"); |
75 hrs_ext_msg(this, "master free list MT safety protocol " | |
76 "at a safepoint")); | |
77 } else { | 79 } else { |
78 guarantee(Heap_lock->owned_by_self(), | 80 guarantee(Heap_lock->owned_by_self(), "master free list MT safety protocol outside a safepoint"); |
79 hrs_ext_msg(this, "master free list MT safety protocol " | |
80 "outside a safepoint")); | |
81 } | 81 } |
82 | |
83 return FreeRegionList::check_mt_safety(); | |
84 } | 82 } |
85 | 83 |
86 //////////////////// SecondaryFreeRegionList //////////////////// | 84 void SecondaryFreeRegionListMtSafeChecker::check() { |
87 | |
88 bool SecondaryFreeRegionList::check_mt_safety() { | |
89 // Secondary Free List MT safety protocol: | 85 // Secondary Free List MT safety protocol: |
90 // Operations on the secondary free list should always be invoked | 86 // Operations on the secondary free list should always be invoked |
91 // while holding the SecondaryFreeList_lock. | 87 // while holding the SecondaryFreeList_lock. |
92 | 88 |
93 guarantee(SecondaryFreeList_lock->owned_by_self(), | 89 guarantee(SecondaryFreeList_lock->owned_by_self(), "secondary free list MT safety protocol"); |
94 hrs_ext_msg(this, "secondary free list MT safety protocol")); | |
95 | |
96 return FreeRegionList::check_mt_safety(); | |
97 } | 90 } |
98 | 91 |
99 //////////////////// OldRegionSet //////////////////// | 92 void OldRegionSetMtSafeChecker::check() { |
100 | |
101 const char* OldRegionSet::verify_region_extra(HeapRegion* hr) { | |
102 if (hr->is_young()) { | |
103 return "the region should not be young"; | |
104 } | |
105 // The superclass will check that the region is not empty and not | |
106 // humongous. | |
107 return HeapRegionSet::verify_region_extra(hr); | |
108 } | |
109 | |
110 //////////////////// MasterOldRegionSet //////////////////// | |
111 | |
112 bool MasterOldRegionSet::check_mt_safety() { | |
113 // Master Old Set MT safety protocol: | 93 // Master Old Set MT safety protocol: |
114 // (a) If we're at a safepoint, operations on the master old set | 94 // (a) If we're at a safepoint, operations on the master old set |
115 // should be invoked: | 95 // should be invoked: |
116 // - by the VM thread (which will serialize them), or | 96 // - by the VM thread (which will serialize them), or |
117 // - by the GC workers while holding the FreeList_lock, if we're | 97 // - by the GC workers while holding the FreeList_lock, if we're |
122 // safepoint for a cleanup pause. | 102 // safepoint for a cleanup pause. |
123 // (b) If we're not at a safepoint, operations on the master old set | 103 // (b) If we're not at a safepoint, operations on the master old set |
124 // should be invoked while holding the Heap_lock. | 104 // should be invoked while holding the Heap_lock. |
125 | 105 |
126 if (SafepointSynchronize::is_at_safepoint()) { | 106 if (SafepointSynchronize::is_at_safepoint()) { |
127 guarantee(Thread::current()->is_VM_thread() || | 107 guarantee(Thread::current()->is_VM_thread() |
128 _phase == HRSPhaseEvacuation && FreeList_lock->owned_by_self() || | 108 || FreeList_lock->owned_by_self() || OldSets_lock->owned_by_self(), |
129 _phase == HRSPhaseCleanup && OldSets_lock->owned_by_self(), | 109 "master old set MT safety protocol at a safepoint"); |
130 hrs_ext_msg(this, "master old set MT safety protocol " | |
131 "at a safepoint")); | |
132 } else { | 110 } else { |
133 guarantee(Heap_lock->owned_by_self(), | 111 guarantee(Heap_lock->owned_by_self(), "master old set MT safety protocol outside a safepoint"); |
134 hrs_ext_msg(this, "master old set MT safety protocol " | |
135 "outside a safepoint")); | |
136 } | 112 } |
137 | |
138 return OldRegionSet::check_mt_safety(); | |
139 } | 113 } |
140 | 114 |
141 //////////////////// HumongousRegionSet //////////////////// | 115 void HumongousRegionSetMtSafeChecker::check() { |
142 | 116 // Humongous Set MT safety protocol: |
143 const char* HumongousRegionSet::verify_region_extra(HeapRegion* hr) { | |
144 if (hr->is_young()) { | |
145 return "the region should not be young"; | |
146 } | |
147 // The superclass will check that the region is not empty and | |
148 // humongous. | |
149 return HeapRegionSet::verify_region_extra(hr); | |
150 } | |
151 | |
152 //////////////////// MasterHumongousRegionSet //////////////////// | |
153 | |
154 bool MasterHumongousRegionSet::check_mt_safety() { | |
155 // Master Humongous Set MT safety protocol: | |
156 // (a) If we're at a safepoint, operations on the master humongous | 117 // (a) If we're at a safepoint, operations on the master humongous |
157 // set should be invoked by either the VM thread (which will | 118 // set should be invoked by either the VM thread (which will |
158 // serialize them) or by the GC workers while holding the | 119 // serialize them) or by the GC workers while holding the |
159 // OldSets_lock. | 120 // OldSets_lock. |
160 // (b) If we're not at a safepoint, operations on the master | 121 // (b) If we're not at a safepoint, operations on the master |
161 // humongous set should be invoked while holding the Heap_lock. | 122 // humongous set should be invoked while holding the Heap_lock. |
162 | 123 |
163 if (SafepointSynchronize::is_at_safepoint()) { | 124 if (SafepointSynchronize::is_at_safepoint()) { |
164 guarantee(Thread::current()->is_VM_thread() || | 125 guarantee(Thread::current()->is_VM_thread() || |
165 OldSets_lock->owned_by_self(), | 126 OldSets_lock->owned_by_self(), |
166 hrs_ext_msg(this, "master humongous set MT safety protocol " | 127 "master humongous set MT safety protocol at a safepoint"); |
167 "at a safepoint")); | |
168 } else { | 128 } else { |
169 guarantee(Heap_lock->owned_by_self(), | 129 guarantee(Heap_lock->owned_by_self(), |
170 hrs_ext_msg(this, "master humongous set MT safety protocol " | 130 "master humongous set MT safety protocol outside a safepoint"); |
171 "outside a safepoint")); | |
172 } | 131 } |
173 | |
174 return HumongousRegionSet::check_mt_safety(); | |
175 } | 132 } |