Mercurial > hg > graal-compiler
comparison src/share/vm/gc_implementation/g1/heapRegionSet.inline.hpp @ 17736:58fc1b1523dc
8034079: G1: Refactor the HeapRegionSet hierarchy
Reviewed-by: tschatzl, pliden
author | brutisso |
---|---|
date | Fri, 14 Mar 2014 10:15:46 +0100 |
parents | a2f7274eb6ef |
children | 8ee855b4e667 |
comparison
equal
deleted
inserted
replaced
17735:8f28240318a2 | 17736:58fc1b1523dc |
---|---|
25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP | 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP |
26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP | 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP |
27 | 27 |
28 #include "gc_implementation/g1/heapRegionSet.hpp" | 28 #include "gc_implementation/g1/heapRegionSet.hpp" |
29 | 29 |
30 //////////////////// HeapRegionSetBase //////////////////// | 30 inline void HeapRegionSetBase::add(HeapRegion* hr) { |
31 check_mt_safety(); | |
32 assert(hr->containing_set() == NULL, hrs_ext_msg(this, "should not already have a containing set %u")); | |
33 assert(hr->next() == NULL, hrs_ext_msg(this, "should not already be linked")); | |
31 | 34 |
32 inline void HeapRegionSetBase::update_for_addition(HeapRegion* hr) { | 35 _count.increment(1u, hr->capacity()); |
33 // Assumes the caller has already verified the region. | 36 hr->set_containing_set(this); |
34 | 37 verify_region(hr); |
35 _length += 1; | |
36 _region_num += hr->region_num(); | |
37 _total_used_bytes += hr->used(); | |
38 } | 38 } |
39 | 39 |
40 inline void HeapRegionSetBase::add_internal(HeapRegion* hr) { | 40 inline void HeapRegionSetBase::remove(HeapRegion* hr) { |
41 hrs_assert_region_ok(this, hr, NULL); | 41 check_mt_safety(); |
42 assert(hr->next() == NULL, hrs_ext_msg(this, "should not already be linked")); | 42 verify_region(hr); |
43 | |
44 update_for_addition(hr); | |
45 hr->set_containing_set(this); | |
46 } | |
47 | |
48 inline void HeapRegionSetBase::update_for_removal(HeapRegion* hr) { | |
49 // Assumes the caller has already verified the region. | |
50 assert(_length > 0, hrs_ext_msg(this, "pre-condition")); | |
51 _length -= 1; | |
52 | |
53 uint region_num_diff = hr->region_num(); | |
54 assert(region_num_diff <= _region_num, | |
55 hrs_err_msg("[%s] region's region num: %u " | |
56 "should be <= region num: %u", | |
57 name(), region_num_diff, _region_num)); | |
58 _region_num -= region_num_diff; | |
59 | |
60 size_t used_bytes = hr->used(); | |
61 assert(used_bytes <= _total_used_bytes, | |
62 hrs_err_msg("[%s] region's used bytes: "SIZE_FORMAT" " | |
63 "should be <= used bytes: "SIZE_FORMAT, | |
64 name(), used_bytes, _total_used_bytes)); | |
65 _total_used_bytes -= used_bytes; | |
66 } | |
67 | |
68 inline void HeapRegionSetBase::remove_internal(HeapRegion* hr) { | |
69 hrs_assert_region_ok(this, hr, this); | |
70 assert(hr->next() == NULL, hrs_ext_msg(this, "should already be unlinked")); | 43 assert(hr->next() == NULL, hrs_ext_msg(this, "should already be unlinked")); |
71 | 44 |
72 hr->set_containing_set(NULL); | 45 hr->set_containing_set(NULL); |
73 update_for_removal(hr); | 46 assert(_count.length() > 0, hrs_ext_msg(this, "pre-condition")); |
47 _count.decrement(1u, hr->capacity()); | |
74 } | 48 } |
75 | 49 |
76 //////////////////// HeapRegionSet //////////////////// | 50 inline void FreeRegionList::add_as_head(HeapRegion* hr) { |
77 | |
78 inline void HeapRegionSet::add(HeapRegion* hr) { | |
79 hrs_assert_mt_safety_ok(this); | |
80 // add_internal() will verify the region. | |
81 add_internal(hr); | |
82 } | |
83 | |
84 inline void HeapRegionSet::remove(HeapRegion* hr) { | |
85 hrs_assert_mt_safety_ok(this); | |
86 // remove_internal() will verify the region. | |
87 remove_internal(hr); | |
88 } | |
89 | |
90 inline void HeapRegionSet::remove_with_proxy(HeapRegion* hr, | |
91 HeapRegionSet* proxy_set) { | |
92 // No need to fo the MT safety check here given that this method | |
93 // does not update the contents of the set but instead accumulates | |
94 // the changes in proxy_set which is assumed to be thread-local. | |
95 hrs_assert_sets_match(this, proxy_set); | |
96 hrs_assert_region_ok(this, hr, this); | |
97 | |
98 hr->set_containing_set(NULL); | |
99 proxy_set->update_for_addition(hr); | |
100 } | |
101 | |
102 //////////////////// HeapRegionLinkedList //////////////////// | |
103 | |
104 inline void HeapRegionLinkedList::add_as_head(HeapRegion* hr) { | |
105 hrs_assert_mt_safety_ok(this); | |
106 assert((length() == 0 && _head == NULL && _tail == NULL) || | 51 assert((length() == 0 && _head == NULL && _tail == NULL) || |
107 (length() > 0 && _head != NULL && _tail != NULL), | 52 (length() > 0 && _head != NULL && _tail != NULL), |
108 hrs_ext_msg(this, "invariant")); | 53 hrs_ext_msg(this, "invariant")); |
109 // add_internal() will verify the region. | 54 // add() will verify the region and check mt safety. |
110 add_internal(hr); | 55 add(hr); |
111 | 56 |
112 // Now link the region. | 57 // Now link the region. |
113 if (_head != NULL) { | 58 if (_head != NULL) { |
114 hr->set_next(_head); | 59 hr->set_next(_head); |
115 } else { | 60 } else { |
116 _tail = hr; | 61 _tail = hr; |
117 } | 62 } |
118 _head = hr; | 63 _head = hr; |
119 } | 64 } |
120 | 65 |
121 inline void HeapRegionLinkedList::add_as_tail(HeapRegion* hr) { | 66 inline void FreeRegionList::add_as_tail(HeapRegion* hr) { |
122 hrs_assert_mt_safety_ok(this); | 67 check_mt_safety(); |
123 assert((length() == 0 && _head == NULL && _tail == NULL) || | 68 assert((length() == 0 && _head == NULL && _tail == NULL) || |
124 (length() > 0 && _head != NULL && _tail != NULL), | 69 (length() > 0 && _head != NULL && _tail != NULL), |
125 hrs_ext_msg(this, "invariant")); | 70 hrs_ext_msg(this, "invariant")); |
126 // add_internal() will verify the region. | 71 // add() will verify the region and check mt safety |
127 add_internal(hr); | 72 add(hr); |
128 | 73 |
129 // Now link the region. | 74 // Now link the region. |
130 if (_tail != NULL) { | 75 if (_tail != NULL) { |
131 _tail->set_next(hr); | 76 _tail->set_next(hr); |
132 } else { | 77 } else { |
133 _head = hr; | 78 _head = hr; |
134 } | 79 } |
135 _tail = hr; | 80 _tail = hr; |
136 } | 81 } |
137 | 82 |
138 inline HeapRegion* HeapRegionLinkedList::remove_head() { | 83 inline HeapRegion* FreeRegionList::remove_head() { |
139 hrs_assert_mt_safety_ok(this); | |
140 assert(!is_empty(), hrs_ext_msg(this, "the list should not be empty")); | 84 assert(!is_empty(), hrs_ext_msg(this, "the list should not be empty")); |
141 assert(length() > 0 && _head != NULL && _tail != NULL, | 85 assert(length() > 0 && _head != NULL && _tail != NULL, |
142 hrs_ext_msg(this, "invariant")); | 86 hrs_ext_msg(this, "invariant")); |
143 | 87 |
144 // We need to unlink it first. | 88 // We need to unlink it first. |
147 if (_head == NULL) { | 91 if (_head == NULL) { |
148 _tail = NULL; | 92 _tail = NULL; |
149 } | 93 } |
150 hr->set_next(NULL); | 94 hr->set_next(NULL); |
151 | 95 |
152 // remove_internal() will verify the region. | 96 // remove() will verify the region and check mt safety |
153 remove_internal(hr); | 97 remove(hr); |
154 return hr; | 98 return hr; |
155 } | 99 } |
156 | 100 |
157 inline HeapRegion* HeapRegionLinkedList::remove_head_or_null() { | 101 inline HeapRegion* FreeRegionList::remove_head_or_null() { |
158 hrs_assert_mt_safety_ok(this); | 102 check_mt_safety(); |
159 | |
160 if (!is_empty()) { | 103 if (!is_empty()) { |
161 return remove_head(); | 104 return remove_head(); |
162 } else { | 105 } else { |
163 return NULL; | 106 return NULL; |
164 } | 107 } |