Mercurial > hg > truffle
comparison src/share/vm/gc_implementation/g1/heapRegionSet.inline.hpp @ 18041:52b4284cb496
Merge with jdk8u20-b26
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Wed, 15 Oct 2014 16:02:50 +0200 |
parents | 86b4965f0c9a 14bd75c9dbfa |
children | 7848fc12602b |
comparison
equal
deleted
inserted
replaced
17606:45d7b2c7029d | 18041:52b4284cb496 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
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 | 31 check_mt_safety(); |
32 inline void HeapRegionSetBase::update_for_addition(HeapRegion* hr) { | 32 assert(hr->containing_set() == NULL, hrs_ext_msg(this, "should not already have a containing set %u")); |
33 // Assumes the caller has already verified the region. | 33 assert(hr->next() == NULL && hr->prev() == NULL, hrs_ext_msg(this, "should not already be linked")); |
34 | 34 |
35 _length += 1; | 35 _count.increment(1u, hr->capacity()); |
36 _region_num += hr->region_num(); | |
37 _total_used_bytes += hr->used(); | |
38 } | |
39 | |
40 inline void HeapRegionSetBase::add_internal(HeapRegion* hr) { | |
41 hrs_assert_region_ok(this, hr, NULL); | |
42 assert(hr->next() == NULL, hrs_ext_msg(this, "should not already be linked")); | |
43 | |
44 update_for_addition(hr); | |
45 hr->set_containing_set(this); | 36 hr->set_containing_set(this); |
46 } | 37 verify_region(hr); |
47 | 38 } |
48 inline void HeapRegionSetBase::update_for_removal(HeapRegion* hr) { | 39 |
49 // Assumes the caller has already verified the region. | 40 inline void HeapRegionSetBase::remove(HeapRegion* hr) { |
50 assert(_length > 0, hrs_ext_msg(this, "pre-condition")); | 41 check_mt_safety(); |
51 _length -= 1; | 42 verify_region(hr); |
52 | 43 assert(hr->next() == NULL && hr->prev() == NULL, hrs_ext_msg(this, "should already be unlinked")); |
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")); | |
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")); |
74 } | 47 _count.decrement(1u, hr->capacity()); |
75 | 48 } |
76 //////////////////// HeapRegionSet //////////////////// | 49 |
77 | 50 inline void FreeRegionList::add_ordered(HeapRegion* hr) { |
78 inline void HeapRegionSet::add(HeapRegion* hr) { | 51 check_mt_safety(); |
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) || | 52 assert((length() == 0 && _head == NULL && _tail == NULL) || |
107 (length() > 0 && _head != NULL && _tail != NULL), | 53 (length() > 0 && _head != NULL && _tail != NULL), |
108 hrs_ext_msg(this, "invariant")); | 54 hrs_ext_msg(this, "invariant")); |
109 // add_internal() will verify the region. | 55 // add() will verify the region and check mt safety. |
110 add_internal(hr); | 56 add(hr); |
57 | |
58 // Now link the region | |
59 if (_head != NULL) { | |
60 HeapRegion* curr; | |
61 | |
62 if (_last != NULL && _last->hrs_index() < hr->hrs_index()) { | |
63 curr = _last; | |
64 } else { | |
65 curr = _head; | |
66 } | |
67 | |
68 // Find first entry with a Region Index larger than entry to insert. | |
69 while (curr != NULL && curr->hrs_index() < hr->hrs_index()) { | |
70 curr = curr->next(); | |
71 } | |
72 | |
73 hr->set_next(curr); | |
74 | |
75 if (curr == NULL) { | |
76 // Adding at the end | |
77 hr->set_prev(_tail); | |
78 _tail->set_next(hr); | |
79 _tail = hr; | |
80 } else if (curr->prev() == NULL) { | |
81 // Adding at the beginning | |
82 hr->set_prev(NULL); | |
83 _head = hr; | |
84 curr->set_prev(hr); | |
85 } else { | |
86 hr->set_prev(curr->prev()); | |
87 hr->prev()->set_next(hr); | |
88 curr->set_prev(hr); | |
89 } | |
90 } else { | |
91 // The list was empty | |
92 _tail = hr; | |
93 _head = hr; | |
94 } | |
95 _last = hr; | |
96 } | |
97 | |
98 inline void FreeRegionList::add_as_head(HeapRegion* hr) { | |
99 assert((length() == 0 && _head == NULL && _tail == NULL) || | |
100 (length() > 0 && _head != NULL && _tail != NULL), | |
101 hrs_ext_msg(this, "invariant")); | |
102 // add() will verify the region and check mt safety. | |
103 add(hr); | |
111 | 104 |
112 // Now link the region. | 105 // Now link the region. |
113 if (_head != NULL) { | 106 if (_head != NULL) { |
114 hr->set_next(_head); | 107 hr->set_next(_head); |
108 _head->set_prev(hr); | |
115 } else { | 109 } else { |
116 _tail = hr; | 110 _tail = hr; |
117 } | 111 } |
118 _head = hr; | 112 _head = hr; |
119 } | 113 } |
120 | 114 |
121 inline void HeapRegionLinkedList::add_as_tail(HeapRegion* hr) { | 115 inline void FreeRegionList::add_as_tail(HeapRegion* hr) { |
122 hrs_assert_mt_safety_ok(this); | 116 check_mt_safety(); |
123 assert((length() == 0 && _head == NULL && _tail == NULL) || | 117 assert((length() == 0 && _head == NULL && _tail == NULL) || |
124 (length() > 0 && _head != NULL && _tail != NULL), | 118 (length() > 0 && _head != NULL && _tail != NULL), |
125 hrs_ext_msg(this, "invariant")); | 119 hrs_ext_msg(this, "invariant")); |
126 // add_internal() will verify the region. | 120 // add() will verify the region and check mt safety. |
127 add_internal(hr); | 121 add(hr); |
128 | 122 |
129 // Now link the region. | 123 // Now link the region. |
130 if (_tail != NULL) { | 124 if (_tail != NULL) { |
131 _tail->set_next(hr); | 125 _tail->set_next(hr); |
126 hr->set_prev(_tail); | |
132 } else { | 127 } else { |
133 _head = hr; | 128 _head = hr; |
134 } | 129 } |
135 _tail = hr; | 130 _tail = hr; |
136 } | 131 } |
137 | 132 |
138 inline HeapRegion* HeapRegionLinkedList::remove_head() { | 133 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")); | 134 assert(!is_empty(), hrs_ext_msg(this, "the list should not be empty")); |
141 assert(length() > 0 && _head != NULL && _tail != NULL, | 135 assert(length() > 0 && _head != NULL && _tail != NULL, |
142 hrs_ext_msg(this, "invariant")); | 136 hrs_ext_msg(this, "invariant")); |
143 | 137 |
144 // We need to unlink it first. | 138 // We need to unlink it first. |
145 HeapRegion* hr = _head; | 139 HeapRegion* hr = _head; |
146 _head = hr->next(); | 140 _head = hr->next(); |
147 if (_head == NULL) { | 141 if (_head == NULL) { |
148 _tail = NULL; | 142 _tail = NULL; |
143 } else { | |
144 _head->set_prev(NULL); | |
149 } | 145 } |
150 hr->set_next(NULL); | 146 hr->set_next(NULL); |
151 | 147 |
152 // remove_internal() will verify the region. | 148 if (_last == hr) { |
153 remove_internal(hr); | 149 _last = NULL; |
150 } | |
151 | |
152 // remove() will verify the region and check mt safety. | |
153 remove(hr); | |
154 return hr; | 154 return hr; |
155 } | 155 } |
156 | 156 |
157 inline HeapRegion* HeapRegionLinkedList::remove_head_or_null() { | 157 inline HeapRegion* FreeRegionList::remove_head_or_null() { |
158 hrs_assert_mt_safety_ok(this); | 158 check_mt_safety(); |
159 | |
160 if (!is_empty()) { | 159 if (!is_empty()) { |
161 return remove_head(); | 160 return remove_head(); |
162 } else { | 161 } else { |
163 return NULL; | 162 return NULL; |
164 } | 163 } |
165 } | 164 } |
166 | 165 |
166 inline HeapRegion* FreeRegionList::remove_tail() { | |
167 assert(!is_empty(), hrs_ext_msg(this, "The list should not be empty")); | |
168 assert(length() > 0 && _head != NULL && _tail != NULL, | |
169 hrs_ext_msg(this, "invariant")); | |
170 | |
171 // We need to unlink it first | |
172 HeapRegion* hr = _tail; | |
173 | |
174 _tail = hr->prev(); | |
175 if (_tail == NULL) { | |
176 _head = NULL; | |
177 } else { | |
178 _tail->set_next(NULL); | |
179 } | |
180 hr->set_prev(NULL); | |
181 | |
182 if (_last == hr) { | |
183 _last = NULL; | |
184 } | |
185 | |
186 // remove() will verify the region and check mt safety. | |
187 remove(hr); | |
188 return hr; | |
189 } | |
190 | |
191 inline HeapRegion* FreeRegionList::remove_tail_or_null() { | |
192 check_mt_safety(); | |
193 | |
194 if (!is_empty()) { | |
195 return remove_tail(); | |
196 } else { | |
197 return NULL; | |
198 } | |
199 } | |
200 | |
201 inline HeapRegion* FreeRegionList::remove_region(bool from_head) { | |
202 if (from_head) { | |
203 return remove_head_or_null(); | |
204 } else { | |
205 return remove_tail_or_null(); | |
206 } | |
207 } | |
208 | |
167 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP | 209 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP |