55 guarantee(nextTC->size() == size(), "wrong size"); |
64 guarantee(nextTC->size() == size(), "wrong size"); |
56 nextTC->verify_tree_chunk_list(); |
65 nextTC->verify_tree_chunk_list(); |
57 } |
66 } |
58 } |
67 } |
59 |
68 |
60 |
69 template <class Chunk_t, template <class> class FreeList_t> |
61 template <class Chunk> |
70 TreeList<Chunk_t, FreeList_t>::TreeList() {} |
62 TreeList<Chunk>* TreeList<Chunk>::as_TreeList(TreeChunk<Chunk>* tc) { |
71 |
|
72 template <class Chunk_t, template <class> class FreeList_t> |
|
73 TreeList<Chunk_t, FreeList_t>* |
|
74 TreeList<Chunk_t, FreeList_t>::as_TreeList(TreeChunk<Chunk_t,FreeList_t>* tc) { |
63 // This first free chunk in the list will be the tree list. |
75 // This first free chunk in the list will be the tree list. |
64 assert(tc->size() >= BinaryTreeDictionary<Chunk>::min_tree_chunk_size, "Chunk is too small for a TreeChunk"); |
76 assert((tc->size() >= (TreeChunk<Chunk_t, FreeList_t>::min_size())), |
65 TreeList<Chunk>* tl = tc->embedded_list(); |
77 "Chunk is too small for a TreeChunk"); |
|
78 TreeList<Chunk_t, FreeList_t>* tl = tc->embedded_list(); |
|
79 tl->initialize(); |
66 tc->set_list(tl); |
80 tc->set_list(tl); |
67 #ifdef ASSERT |
|
68 tl->set_protecting_lock(NULL); |
|
69 #endif |
|
70 tl->set_hint(0); |
|
71 tl->set_size(tc->size()); |
81 tl->set_size(tc->size()); |
72 tl->link_head(tc); |
82 tl->link_head(tc); |
73 tl->link_tail(tc); |
83 tl->link_tail(tc); |
74 tl->set_count(1); |
84 tl->set_count(1); |
75 tl->init_statistics(true /* split_birth */); |
85 |
76 tl->set_parent(NULL); |
|
77 tl->set_left(NULL); |
|
78 tl->set_right(NULL); |
|
79 return tl; |
86 return tl; |
80 } |
87 } |
81 |
88 |
82 template <class Chunk> |
89 |
83 TreeList<Chunk>* TreeList<Chunk>::as_TreeList(HeapWord* addr, size_t size) { |
90 template <class Chunk_t, template <class> class FreeList_t> |
84 TreeChunk<Chunk>* tc = (TreeChunk<Chunk>*) addr; |
91 TreeList<Chunk_t, FreeList_t>* |
85 assert(size >= BinaryTreeDictionary<Chunk>::min_tree_chunk_size, "Chunk is too small for a TreeChunk"); |
92 get_chunk(size_t size, enum FreeBlockDictionary<Chunk_t>::Dither dither) { |
86 // The space in the heap will have been mangled initially but |
93 FreeBlockDictionary<Chunk_t>::verify_par_locked(); |
87 // is not remangled when a free chunk is returned to the free list |
94 Chunk_t* res = get_chunk_from_tree(size, dither); |
|
95 assert(res == NULL || res->is_free(), |
|
96 "Should be returning a free chunk"); |
|
97 assert(dither != FreeBlockDictionary<Chunk_t>::exactly || |
|
98 res->size() == size, "Not correct size"); |
|
99 return res; |
|
100 } |
|
101 |
|
102 template <class Chunk_t, template <class> class FreeList_t> |
|
103 TreeList<Chunk_t, FreeList_t>* |
|
104 TreeList<Chunk_t, FreeList_t>::as_TreeList(HeapWord* addr, size_t size) { |
|
105 TreeChunk<Chunk_t, FreeList_t>* tc = (TreeChunk<Chunk_t, FreeList_t>*) addr; |
|
106 assert((size >= TreeChunk<Chunk_t, FreeList_t>::min_size()), |
|
107 "Chunk is too small for a TreeChunk"); |
|
108 // The space will have been mangled initially but |
|
109 // is not remangled when a Chunk_t is returned to the free list |
88 // (since it is used to maintain the chunk on the free list). |
110 // (since it is used to maintain the chunk on the free list). |
89 assert((ZapUnusedHeapArea && |
111 tc->assert_is_mangled(); |
90 SpaceMangler::is_mangled((HeapWord*) tc->size_addr()) && |
|
91 SpaceMangler::is_mangled((HeapWord*) tc->prev_addr()) && |
|
92 SpaceMangler::is_mangled((HeapWord*) tc->next_addr())) || |
|
93 (tc->size() == 0 && tc->prev() == NULL && tc->next() == NULL), |
|
94 "Space should be clear or mangled"); |
|
95 tc->set_size(size); |
112 tc->set_size(size); |
96 tc->link_prev(NULL); |
113 tc->link_prev(NULL); |
97 tc->link_next(NULL); |
114 tc->link_next(NULL); |
98 TreeList<Chunk>* tl = TreeList<Chunk>::as_TreeList(tc); |
115 TreeList<Chunk_t, FreeList_t>* tl = TreeList<Chunk_t, FreeList_t>::as_TreeList(tc); |
99 return tl; |
116 return tl; |
100 } |
117 } |
101 |
118 |
102 template <class Chunk> |
119 |
103 TreeList<Chunk>* TreeList<Chunk>::remove_chunk_replace_if_needed(TreeChunk<Chunk>* tc) { |
120 #ifndef SERIALGC |
104 |
121 // Specialize for AdaptiveFreeList which tries to avoid |
105 TreeList<Chunk>* retTL = this; |
122 // splitting a chunk of a size that is under populated in favor of |
106 Chunk* list = head(); |
123 // an over populated size. The general get_better_list() just returns |
|
124 // the current list. |
|
125 template <> |
|
126 TreeList<FreeChunk, AdaptiveFreeList>* |
|
127 TreeList<FreeChunk, AdaptiveFreeList>::get_better_list( |
|
128 BinaryTreeDictionary<FreeChunk, ::AdaptiveFreeList>* dictionary) { |
|
129 // A candidate chunk has been found. If it is already under |
|
130 // populated, get a chunk associated with the hint for this |
|
131 // chunk. |
|
132 |
|
133 TreeList<FreeChunk, ::AdaptiveFreeList>* curTL = this; |
|
134 if (surplus() <= 0) { |
|
135 /* Use the hint to find a size with a surplus, and reset the hint. */ |
|
136 TreeList<FreeChunk, ::AdaptiveFreeList>* hintTL = this; |
|
137 while (hintTL->hint() != 0) { |
|
138 assert(hintTL->hint() > hintTL->size(), |
|
139 "hint points in the wrong direction"); |
|
140 hintTL = dictionary->find_list(hintTL->hint()); |
|
141 assert(curTL != hintTL, "Infinite loop"); |
|
142 if (hintTL == NULL || |
|
143 hintTL == curTL /* Should not happen but protect against it */ ) { |
|
144 // No useful hint. Set the hint to NULL and go on. |
|
145 curTL->set_hint(0); |
|
146 break; |
|
147 } |
|
148 assert(hintTL->size() > curTL->size(), "hint is inconsistent"); |
|
149 if (hintTL->surplus() > 0) { |
|
150 // The hint led to a list that has a surplus. Use it. |
|
151 // Set the hint for the candidate to an overpopulated |
|
152 // size. |
|
153 curTL->set_hint(hintTL->size()); |
|
154 // Change the candidate. |
|
155 curTL = hintTL; |
|
156 break; |
|
157 } |
|
158 } |
|
159 } |
|
160 return curTL; |
|
161 } |
|
162 #endif // SERIALGC |
|
163 |
|
164 template <class Chunk_t, template <class> class FreeList_t> |
|
165 TreeList<Chunk_t, FreeList_t>* |
|
166 TreeList<Chunk_t, FreeList_t>::get_better_list( |
|
167 BinaryTreeDictionary<Chunk_t, FreeList_t>* dictionary) { |
|
168 return this; |
|
169 } |
|
170 |
|
171 template <class Chunk_t, template <class> class FreeList_t> |
|
172 TreeList<Chunk_t, FreeList_t>* TreeList<Chunk_t, FreeList_t>::remove_chunk_replace_if_needed(TreeChunk<Chunk_t, FreeList_t>* tc) { |
|
173 |
|
174 TreeList<Chunk_t, FreeList_t>* retTL = this; |
|
175 Chunk_t* list = head(); |
107 assert(!list || list != list->next(), "Chunk on list twice"); |
176 assert(!list || list != list->next(), "Chunk on list twice"); |
108 assert(tc != NULL, "Chunk being removed is NULL"); |
177 assert(tc != NULL, "Chunk being removed is NULL"); |
109 assert(parent() == NULL || this == parent()->left() || |
178 assert(parent() == NULL || this == parent()->left() || |
110 this == parent()->right(), "list is inconsistent"); |
179 this == parent()->right(), "list is inconsistent"); |
111 assert(tc->is_free(), "Header is not marked correctly"); |
180 assert(tc->is_free(), "Header is not marked correctly"); |
112 assert(head() == NULL || head()->prev() == NULL, "list invariant"); |
181 assert(head() == NULL || head()->prev() == NULL, "list invariant"); |
113 assert(tail() == NULL || tail()->next() == NULL, "list invariant"); |
182 assert(tail() == NULL || tail()->next() == NULL, "list invariant"); |
114 |
183 |
115 Chunk* prevFC = tc->prev(); |
184 Chunk_t* prevFC = tc->prev(); |
116 TreeChunk<Chunk>* nextTC = TreeChunk<Chunk>::as_TreeChunk(tc->next()); |
185 TreeChunk<Chunk_t, FreeList_t>* nextTC = TreeChunk<Chunk_t, FreeList_t>::as_TreeChunk(tc->next()); |
117 assert(list != NULL, "should have at least the target chunk"); |
186 assert(list != NULL, "should have at least the target chunk"); |
118 |
187 |
119 // Is this the first item on the list? |
188 // Is this the first item on the list? |
120 if (tc == list) { |
189 if (tc == list) { |
121 // The "getChunk..." functions for a TreeList<Chunk> will not return the |
190 // The "getChunk..." functions for a TreeList<Chunk_t, FreeList_t> will not return the |
122 // first chunk in the list unless it is the last chunk in the list |
191 // first chunk in the list unless it is the last chunk in the list |
123 // because the first chunk is also acting as the tree node. |
192 // because the first chunk is also acting as the tree node. |
124 // When coalescing happens, however, the first chunk in the a tree |
193 // When coalescing happens, however, the first chunk in the a tree |
125 // list can be the start of a free range. Free ranges are removed |
194 // list can be the start of a free range. Free ranges are removed |
126 // from the free lists so that they are not available to be |
195 // from the free lists so that they are not available to be |
127 // allocated when the sweeper yields (giving up the free list lock) |
196 // allocated when the sweeper yields (giving up the free list lock) |
128 // to allow mutator activity. If this chunk is the first in the |
197 // to allow mutator activity. If this chunk is the first in the |
129 // list and is not the last in the list, do the work to copy the |
198 // list and is not the last in the list, do the work to copy the |
130 // TreeList<Chunk> from the first chunk to the next chunk and update all |
199 // TreeList<Chunk_t, FreeList_t> from the first chunk to the next chunk and update all |
131 // the TreeList<Chunk> pointers in the chunks in the list. |
200 // the TreeList<Chunk_t, FreeList_t> pointers in the chunks in the list. |
132 if (nextTC == NULL) { |
201 if (nextTC == NULL) { |
133 assert(prevFC == NULL, "Not last chunk in the list"); |
202 assert(prevFC == NULL, "Not last chunk in the list"); |
134 set_tail(NULL); |
203 set_tail(NULL); |
135 set_head(NULL); |
204 set_head(NULL); |
136 } else { |
205 } else { |
213 assert(retTL->tail() == NULL || retTL->tail()->next() == NULL, |
282 assert(retTL->tail() == NULL || retTL->tail()->next() == NULL, |
214 "list invariant"); |
283 "list invariant"); |
215 return retTL; |
284 return retTL; |
216 } |
285 } |
217 |
286 |
218 template <class Chunk> |
287 template <class Chunk_t, template <class> class FreeList_t> |
219 void TreeList<Chunk>::return_chunk_at_tail(TreeChunk<Chunk>* chunk) { |
288 void TreeList<Chunk_t, FreeList_t>::return_chunk_at_tail(TreeChunk<Chunk_t, FreeList_t>* chunk) { |
220 assert(chunk != NULL, "returning NULL chunk"); |
289 assert(chunk != NULL, "returning NULL chunk"); |
221 assert(chunk->list() == this, "list should be set for chunk"); |
290 assert(chunk->list() == this, "list should be set for chunk"); |
222 assert(tail() != NULL, "The tree list is embedded in the first chunk"); |
291 assert(tail() != NULL, "The tree list is embedded in the first chunk"); |
223 // which means that the list can never be empty. |
292 // which means that the list can never be empty. |
224 assert(!verify_chunk_in_free_list(chunk), "Double entry"); |
293 assert(!verify_chunk_in_free_list(chunk), "Double entry"); |
225 assert(head() == NULL || head()->prev() == NULL, "list invariant"); |
294 assert(head() == NULL || head()->prev() == NULL, "list invariant"); |
226 assert(tail() == NULL || tail()->next() == NULL, "list invariant"); |
295 assert(tail() == NULL || tail()->next() == NULL, "list invariant"); |
227 |
296 |
228 Chunk* fc = tail(); |
297 Chunk_t* fc = tail(); |
229 fc->link_after(chunk); |
298 fc->link_after(chunk); |
230 link_tail(chunk); |
299 link_tail(chunk); |
231 |
300 |
232 assert(!tail() || size() == tail()->size(), "Wrong sized chunk in list"); |
301 assert(!tail() || size() == tail()->size(), "Wrong sized chunk in list"); |
233 increment_count(); |
302 FreeList_t<Chunk_t>::increment_count(); |
234 debug_only(increment_returned_bytes_by(chunk->size()*sizeof(HeapWord));) |
303 debug_only(increment_returned_bytes_by(chunk->size()*sizeof(HeapWord));) |
235 assert(head() == NULL || head()->prev() == NULL, "list invariant"); |
304 assert(head() == NULL || head()->prev() == NULL, "list invariant"); |
236 assert(tail() == NULL || tail()->next() == NULL, "list invariant"); |
305 assert(tail() == NULL || tail()->next() == NULL, "list invariant"); |
237 } |
306 } |
238 |
307 |
239 // Add this chunk at the head of the list. "At the head of the list" |
308 // Add this chunk at the head of the list. "At the head of the list" |
240 // is defined to be after the chunk pointer to by head(). This is |
309 // is defined to be after the chunk pointer to by head(). This is |
241 // because the TreeList<Chunk> is embedded in the first TreeChunk<Chunk> in the |
310 // because the TreeList<Chunk_t, FreeList_t> is embedded in the first TreeChunk<Chunk_t, FreeList_t> in the |
242 // list. See the definition of TreeChunk<Chunk>. |
311 // list. See the definition of TreeChunk<Chunk_t, FreeList_t>. |
243 template <class Chunk> |
312 template <class Chunk_t, template <class> class FreeList_t> |
244 void TreeList<Chunk>::return_chunk_at_head(TreeChunk<Chunk>* chunk) { |
313 void TreeList<Chunk_t, FreeList_t>::return_chunk_at_head(TreeChunk<Chunk_t, FreeList_t>* chunk) { |
245 assert(chunk->list() == this, "list should be set for chunk"); |
314 assert(chunk->list() == this, "list should be set for chunk"); |
246 assert(head() != NULL, "The tree list is embedded in the first chunk"); |
315 assert(head() != NULL, "The tree list is embedded in the first chunk"); |
247 assert(chunk != NULL, "returning NULL chunk"); |
316 assert(chunk != NULL, "returning NULL chunk"); |
248 assert(!verify_chunk_in_free_list(chunk), "Double entry"); |
317 assert(!verify_chunk_in_free_list(chunk), "Double entry"); |
249 assert(head() == NULL || head()->prev() == NULL, "list invariant"); |
318 assert(head() == NULL || head()->prev() == NULL, "list invariant"); |
250 assert(tail() == NULL || tail()->next() == NULL, "list invariant"); |
319 assert(tail() == NULL || tail()->next() == NULL, "list invariant"); |
251 |
320 |
252 Chunk* fc = head()->next(); |
321 Chunk_t* fc = head()->next(); |
253 if (fc != NULL) { |
322 if (fc != NULL) { |
254 chunk->link_after(fc); |
323 chunk->link_after(fc); |
255 } else { |
324 } else { |
256 assert(tail() == NULL, "List is inconsistent"); |
325 assert(tail() == NULL, "List is inconsistent"); |
257 link_tail(chunk); |
326 link_tail(chunk); |
258 } |
327 } |
259 head()->link_after(chunk); |
328 head()->link_after(chunk); |
260 assert(!head() || size() == head()->size(), "Wrong sized chunk in list"); |
329 assert(!head() || size() == head()->size(), "Wrong sized chunk in list"); |
261 increment_count(); |
330 FreeList_t<Chunk_t>::increment_count(); |
262 debug_only(increment_returned_bytes_by(chunk->size()*sizeof(HeapWord));) |
331 debug_only(increment_returned_bytes_by(chunk->size()*sizeof(HeapWord));) |
263 assert(head() == NULL || head()->prev() == NULL, "list invariant"); |
332 assert(head() == NULL || head()->prev() == NULL, "list invariant"); |
264 assert(tail() == NULL || tail()->next() == NULL, "list invariant"); |
333 assert(tail() == NULL || tail()->next() == NULL, "list invariant"); |
265 } |
334 } |
266 |
335 |
267 template <class Chunk> |
336 template <class Chunk_t, template <class> class FreeList_t> |
268 TreeChunk<Chunk>* TreeList<Chunk>::head_as_TreeChunk() { |
337 void TreeChunk<Chunk_t, FreeList_t>::assert_is_mangled() const { |
269 assert(head() == NULL || TreeChunk<Chunk>::as_TreeChunk(head())->list() == this, |
338 assert((ZapUnusedHeapArea && |
|
339 SpaceMangler::is_mangled((HeapWord*) Chunk_t::size_addr()) && |
|
340 SpaceMangler::is_mangled((HeapWord*) Chunk_t::prev_addr()) && |
|
341 SpaceMangler::is_mangled((HeapWord*) Chunk_t::next_addr())) || |
|
342 (size() == 0 && prev() == NULL && next() == NULL), |
|
343 "Space should be clear or mangled"); |
|
344 } |
|
345 |
|
346 template <class Chunk_t, template <class> class FreeList_t> |
|
347 TreeChunk<Chunk_t, FreeList_t>* TreeList<Chunk_t, FreeList_t>::head_as_TreeChunk() { |
|
348 assert(head() == NULL || (TreeChunk<Chunk_t, FreeList_t>::as_TreeChunk(head())->list() == this), |
270 "Wrong type of chunk?"); |
349 "Wrong type of chunk?"); |
271 return TreeChunk<Chunk>::as_TreeChunk(head()); |
350 return TreeChunk<Chunk_t, FreeList_t>::as_TreeChunk(head()); |
272 } |
351 } |
273 |
352 |
274 template <class Chunk> |
353 template <class Chunk_t, template <class> class FreeList_t> |
275 TreeChunk<Chunk>* TreeList<Chunk>::first_available() { |
354 TreeChunk<Chunk_t, FreeList_t>* TreeList<Chunk_t, FreeList_t>::first_available() { |
276 assert(head() != NULL, "The head of the list cannot be NULL"); |
355 assert(head() != NULL, "The head of the list cannot be NULL"); |
277 Chunk* fc = head()->next(); |
356 Chunk_t* fc = head()->next(); |
278 TreeChunk<Chunk>* retTC; |
357 TreeChunk<Chunk_t, FreeList_t>* retTC; |
279 if (fc == NULL) { |
358 if (fc == NULL) { |
280 retTC = head_as_TreeChunk(); |
359 retTC = head_as_TreeChunk(); |
281 } else { |
360 } else { |
282 retTC = TreeChunk<Chunk>::as_TreeChunk(fc); |
361 retTC = TreeChunk<Chunk_t, FreeList_t>::as_TreeChunk(fc); |
283 } |
362 } |
284 assert(retTC->list() == this, "Wrong type of chunk."); |
363 assert(retTC->list() == this, "Wrong type of chunk."); |
285 return retTC; |
364 return retTC; |
286 } |
365 } |
287 |
366 |
288 // Returns the block with the largest heap address amongst |
367 // Returns the block with the largest heap address amongst |
289 // those in the list for this size; potentially slow and expensive, |
368 // those in the list for this size; potentially slow and expensive, |
290 // use with caution! |
369 // use with caution! |
291 template <class Chunk> |
370 template <class Chunk_t, template <class> class FreeList_t> |
292 TreeChunk<Chunk>* TreeList<Chunk>::largest_address() { |
371 TreeChunk<Chunk_t, FreeList_t>* TreeList<Chunk_t, FreeList_t>::largest_address() { |
293 assert(head() != NULL, "The head of the list cannot be NULL"); |
372 assert(head() != NULL, "The head of the list cannot be NULL"); |
294 Chunk* fc = head()->next(); |
373 Chunk_t* fc = head()->next(); |
295 TreeChunk<Chunk>* retTC; |
374 TreeChunk<Chunk_t, FreeList_t>* retTC; |
296 if (fc == NULL) { |
375 if (fc == NULL) { |
297 retTC = head_as_TreeChunk(); |
376 retTC = head_as_TreeChunk(); |
298 } else { |
377 } else { |
299 // walk down the list and return the one with the highest |
378 // walk down the list and return the one with the highest |
300 // heap address among chunks of this size. |
379 // heap address among chunks of this size. |
301 Chunk* last = fc; |
380 Chunk_t* last = fc; |
302 while (fc->next() != NULL) { |
381 while (fc->next() != NULL) { |
303 if ((HeapWord*)last < (HeapWord*)fc) { |
382 if ((HeapWord*)last < (HeapWord*)fc) { |
304 last = fc; |
383 last = fc; |
305 } |
384 } |
306 fc = fc->next(); |
385 fc = fc->next(); |
307 } |
386 } |
308 retTC = TreeChunk<Chunk>::as_TreeChunk(last); |
387 retTC = TreeChunk<Chunk_t, FreeList_t>::as_TreeChunk(last); |
309 } |
388 } |
310 assert(retTC->list() == this, "Wrong type of chunk."); |
389 assert(retTC->list() == this, "Wrong type of chunk."); |
311 return retTC; |
390 return retTC; |
312 } |
391 } |
313 |
392 |
314 template <class Chunk> |
393 template <class Chunk_t, template <class> class FreeList_t> |
315 BinaryTreeDictionary<Chunk>::BinaryTreeDictionary(bool adaptive_freelists, bool splay) : |
394 BinaryTreeDictionary<Chunk_t, FreeList_t>::BinaryTreeDictionary(MemRegion mr) { |
316 _splay(splay), _adaptive_freelists(adaptive_freelists), |
395 assert((mr.byte_size() > min_size()), "minimum chunk size"); |
317 _total_size(0), _total_free_blocks(0), _root(0) {} |
|
318 |
|
319 template <class Chunk> |
|
320 BinaryTreeDictionary<Chunk>::BinaryTreeDictionary(MemRegion mr, |
|
321 bool adaptive_freelists, |
|
322 bool splay): |
|
323 _adaptive_freelists(adaptive_freelists), _splay(splay) |
|
324 { |
|
325 assert(mr.word_size() >= BinaryTreeDictionary<Chunk>::min_tree_chunk_size, "minimum chunk size"); |
|
326 |
396 |
327 reset(mr); |
397 reset(mr); |
328 assert(root()->left() == NULL, "reset check failed"); |
398 assert(root()->left() == NULL, "reset check failed"); |
329 assert(root()->right() == NULL, "reset check failed"); |
399 assert(root()->right() == NULL, "reset check failed"); |
330 assert(root()->head()->next() == NULL, "reset check failed"); |
400 assert(root()->head()->next() == NULL, "reset check failed"); |
331 assert(root()->head()->prev() == NULL, "reset check failed"); |
401 assert(root()->head()->prev() == NULL, "reset check failed"); |
332 assert(total_size() == root()->size(), "reset check failed"); |
402 assert(total_size() == root()->size(), "reset check failed"); |
333 assert(total_free_blocks() == 1, "reset check failed"); |
403 assert(total_free_blocks() == 1, "reset check failed"); |
334 } |
404 } |
335 |
405 |
336 template <class Chunk> |
406 template <class Chunk_t, template <class> class FreeList_t> |
337 void BinaryTreeDictionary<Chunk>::inc_total_size(size_t inc) { |
407 void BinaryTreeDictionary<Chunk_t, FreeList_t>::inc_total_size(size_t inc) { |
338 _total_size = _total_size + inc; |
408 _total_size = _total_size + inc; |
339 } |
409 } |
340 |
410 |
341 template <class Chunk> |
411 template <class Chunk_t, template <class> class FreeList_t> |
342 void BinaryTreeDictionary<Chunk>::dec_total_size(size_t dec) { |
412 void BinaryTreeDictionary<Chunk_t, FreeList_t>::dec_total_size(size_t dec) { |
343 _total_size = _total_size - dec; |
413 _total_size = _total_size - dec; |
344 } |
414 } |
345 |
415 |
346 template <class Chunk> |
416 template <class Chunk_t, template <class> class FreeList_t> |
347 void BinaryTreeDictionary<Chunk>::reset(MemRegion mr) { |
417 void BinaryTreeDictionary<Chunk_t, FreeList_t>::reset(MemRegion mr) { |
348 assert(mr.word_size() >= BinaryTreeDictionary<Chunk>::min_tree_chunk_size, "minimum chunk size"); |
418 assert((mr.byte_size() > min_size()), "minimum chunk size"); |
349 set_root(TreeList<Chunk>::as_TreeList(mr.start(), mr.word_size())); |
419 set_root(TreeList<Chunk_t, FreeList_t>::as_TreeList(mr.start(), mr.word_size())); |
350 set_total_size(mr.word_size()); |
420 set_total_size(mr.word_size()); |
351 set_total_free_blocks(1); |
421 set_total_free_blocks(1); |
352 } |
422 } |
353 |
423 |
354 template <class Chunk> |
424 template <class Chunk_t, template <class> class FreeList_t> |
355 void BinaryTreeDictionary<Chunk>::reset(HeapWord* addr, size_t byte_size) { |
425 void BinaryTreeDictionary<Chunk_t, FreeList_t>::reset(HeapWord* addr, size_t byte_size) { |
356 MemRegion mr(addr, heap_word_size(byte_size)); |
426 MemRegion mr(addr, heap_word_size(byte_size)); |
357 reset(mr); |
427 reset(mr); |
358 } |
428 } |
359 |
429 |
360 template <class Chunk> |
430 template <class Chunk_t, template <class> class FreeList_t> |
361 void BinaryTreeDictionary<Chunk>::reset() { |
431 void BinaryTreeDictionary<Chunk_t, FreeList_t>::reset() { |
362 set_root(NULL); |
432 set_root(NULL); |
363 set_total_size(0); |
433 set_total_size(0); |
364 set_total_free_blocks(0); |
434 set_total_free_blocks(0); |
365 } |
435 } |
366 |
436 |
367 // Get a free block of size at least size from tree, or NULL. |
437 // Get a free block of size at least size from tree, or NULL. |
368 // If a splay step is requested, the removal algorithm (only) incorporates |
438 template <class Chunk_t, template <class> class FreeList_t> |
369 // a splay step as follows: |
439 TreeChunk<Chunk_t, FreeList_t>* |
370 // . the search proceeds down the tree looking for a possible |
440 BinaryTreeDictionary<Chunk_t, FreeList_t>::get_chunk_from_tree( |
371 // match. At the (closest) matching location, an appropriate splay step is applied |
441 size_t size, |
372 // (zig, zig-zig or zig-zag). A chunk of the appropriate size is then returned |
442 enum FreeBlockDictionary<Chunk_t>::Dither dither) |
373 // if available, and if it's the last chunk, the node is deleted. A deteleted |
|
374 // node is replaced in place by its tree successor. |
|
375 template <class Chunk> |
|
376 TreeChunk<Chunk>* |
|
377 BinaryTreeDictionary<Chunk>::get_chunk_from_tree(size_t size, enum FreeBlockDictionary<Chunk>::Dither dither, bool splay) |
|
378 { |
443 { |
379 TreeList<Chunk> *curTL, *prevTL; |
444 TreeList<Chunk_t, FreeList_t> *curTL, *prevTL; |
380 TreeChunk<Chunk>* retTC = NULL; |
445 TreeChunk<Chunk_t, FreeList_t>* retTC = NULL; |
381 assert(size >= BinaryTreeDictionary<Chunk>::min_tree_chunk_size, "minimum chunk size"); |
446 |
|
447 assert((size >= min_size()), "minimum chunk size"); |
382 if (FLSVerifyDictionary) { |
448 if (FLSVerifyDictionary) { |
383 verify_tree(); |
449 verify_tree(); |
384 } |
450 } |
385 // starting at the root, work downwards trying to find match. |
451 // starting at the root, work downwards trying to find match. |
386 // Remember the last node of size too great or too small. |
452 // Remember the last node of size too great or too small. |
766 if (FLSVerifyDictionary) { |
779 if (FLSVerifyDictionary) { |
767 verify_tree(); |
780 verify_tree(); |
768 } |
781 } |
769 } |
782 } |
770 |
783 |
771 template <class Chunk> |
784 template <class Chunk_t, template <class> class FreeList_t> |
772 size_t BinaryTreeDictionary<Chunk>::max_chunk_size() const { |
785 size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::max_chunk_size() const { |
773 FreeBlockDictionary<Chunk>::verify_par_locked(); |
786 FreeBlockDictionary<Chunk_t>::verify_par_locked(); |
774 TreeList<Chunk>* tc = root(); |
787 TreeList<Chunk_t, FreeList_t>* tc = root(); |
775 if (tc == NULL) return 0; |
788 if (tc == NULL) return 0; |
776 for (; tc->right() != NULL; tc = tc->right()); |
789 for (; tc->right() != NULL; tc = tc->right()); |
777 return tc->size(); |
790 return tc->size(); |
778 } |
791 } |
779 |
792 |
780 template <class Chunk> |
793 template <class Chunk_t, template <class> class FreeList_t> |
781 size_t BinaryTreeDictionary<Chunk>::total_list_length(TreeList<Chunk>* tl) const { |
794 size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::total_list_length(TreeList<Chunk_t, FreeList_t>* tl) const { |
782 size_t res; |
795 size_t res; |
783 res = tl->count(); |
796 res = tl->count(); |
784 #ifdef ASSERT |
797 #ifdef ASSERT |
785 size_t cnt; |
798 size_t cnt; |
786 Chunk* tc = tl->head(); |
799 Chunk_t* tc = tl->head(); |
787 for (cnt = 0; tc != NULL; tc = tc->next(), cnt++); |
800 for (cnt = 0; tc != NULL; tc = tc->next(), cnt++); |
788 assert(res == cnt, "The count is not being maintained correctly"); |
801 assert(res == cnt, "The count is not being maintained correctly"); |
789 #endif |
802 #endif |
790 return res; |
803 return res; |
791 } |
804 } |
792 |
805 |
793 template <class Chunk> |
806 template <class Chunk_t, template <class> class FreeList_t> |
794 size_t BinaryTreeDictionary<Chunk>::total_size_in_tree(TreeList<Chunk>* tl) const { |
807 size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::total_size_in_tree(TreeList<Chunk_t, FreeList_t>* tl) const { |
795 if (tl == NULL) |
808 if (tl == NULL) |
796 return 0; |
809 return 0; |
797 return (tl->size() * total_list_length(tl)) + |
810 return (tl->size() * total_list_length(tl)) + |
798 total_size_in_tree(tl->left()) + |
811 total_size_in_tree(tl->left()) + |
799 total_size_in_tree(tl->right()); |
812 total_size_in_tree(tl->right()); |
800 } |
813 } |
801 |
814 |
802 template <class Chunk> |
815 template <class Chunk_t, template <class> class FreeList_t> |
803 double BinaryTreeDictionary<Chunk>::sum_of_squared_block_sizes(TreeList<Chunk>* const tl) const { |
816 double BinaryTreeDictionary<Chunk_t, FreeList_t>::sum_of_squared_block_sizes(TreeList<Chunk_t, FreeList_t>* const tl) const { |
804 if (tl == NULL) { |
817 if (tl == NULL) { |
805 return 0.0; |
818 return 0.0; |
806 } |
819 } |
807 double size = (double)(tl->size()); |
820 double size = (double)(tl->size()); |
808 double curr = size * size * total_list_length(tl); |
821 double curr = size * size * total_list_length(tl); |
809 curr += sum_of_squared_block_sizes(tl->left()); |
822 curr += sum_of_squared_block_sizes(tl->left()); |
810 curr += sum_of_squared_block_sizes(tl->right()); |
823 curr += sum_of_squared_block_sizes(tl->right()); |
811 return curr; |
824 return curr; |
812 } |
825 } |
813 |
826 |
814 template <class Chunk> |
827 template <class Chunk_t, template <class> class FreeList_t> |
815 size_t BinaryTreeDictionary<Chunk>::total_free_blocks_in_tree(TreeList<Chunk>* tl) const { |
828 size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::total_free_blocks_in_tree(TreeList<Chunk_t, FreeList_t>* tl) const { |
816 if (tl == NULL) |
829 if (tl == NULL) |
817 return 0; |
830 return 0; |
818 return total_list_length(tl) + |
831 return total_list_length(tl) + |
819 total_free_blocks_in_tree(tl->left()) + |
832 total_free_blocks_in_tree(tl->left()) + |
820 total_free_blocks_in_tree(tl->right()); |
833 total_free_blocks_in_tree(tl->right()); |
821 } |
834 } |
822 |
835 |
823 template <class Chunk> |
836 template <class Chunk_t, template <class> class FreeList_t> |
824 size_t BinaryTreeDictionary<Chunk>::num_free_blocks() const { |
837 size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::num_free_blocks() const { |
825 assert(total_free_blocks_in_tree(root()) == total_free_blocks(), |
838 assert(total_free_blocks_in_tree(root()) == total_free_blocks(), |
826 "_total_free_blocks inconsistency"); |
839 "_total_free_blocks inconsistency"); |
827 return total_free_blocks(); |
840 return total_free_blocks(); |
828 } |
841 } |
829 |
842 |
830 template <class Chunk> |
843 template <class Chunk_t, template <class> class FreeList_t> |
831 size_t BinaryTreeDictionary<Chunk>::tree_height_helper(TreeList<Chunk>* tl) const { |
844 size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::tree_height_helper(TreeList<Chunk_t, FreeList_t>* tl) const { |
832 if (tl == NULL) |
845 if (tl == NULL) |
833 return 0; |
846 return 0; |
834 return 1 + MAX2(tree_height_helper(tl->left()), |
847 return 1 + MAX2(tree_height_helper(tl->left()), |
835 tree_height_helper(tl->right())); |
848 tree_height_helper(tl->right())); |
836 } |
849 } |
837 |
850 |
838 template <class Chunk> |
851 template <class Chunk_t, template <class> class FreeList_t> |
839 size_t BinaryTreeDictionary<Chunk>::treeHeight() const { |
852 size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::tree_height() const { |
840 return tree_height_helper(root()); |
853 return tree_height_helper(root()); |
841 } |
854 } |
842 |
855 |
843 template <class Chunk> |
856 template <class Chunk_t, template <class> class FreeList_t> |
844 size_t BinaryTreeDictionary<Chunk>::total_nodes_helper(TreeList<Chunk>* tl) const { |
857 size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::total_nodes_helper(TreeList<Chunk_t, FreeList_t>* tl) const { |
845 if (tl == NULL) { |
858 if (tl == NULL) { |
846 return 0; |
859 return 0; |
847 } |
860 } |
848 return 1 + total_nodes_helper(tl->left()) + |
861 return 1 + total_nodes_helper(tl->left()) + |
849 total_nodes_helper(tl->right()); |
862 total_nodes_helper(tl->right()); |
850 } |
863 } |
851 |
864 |
852 template <class Chunk> |
865 template <class Chunk_t, template <class> class FreeList_t> |
853 size_t BinaryTreeDictionary<Chunk>::total_nodes_in_tree(TreeList<Chunk>* tl) const { |
866 size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::total_nodes_in_tree(TreeList<Chunk_t, FreeList_t>* tl) const { |
854 return total_nodes_helper(root()); |
867 return total_nodes_helper(root()); |
855 } |
868 } |
856 |
869 |
857 template <class Chunk> |
870 template <class Chunk_t, template <class> class FreeList_t> |
858 void BinaryTreeDictionary<Chunk>::dict_census_udpate(size_t size, bool split, bool birth){ |
871 void BinaryTreeDictionary<Chunk_t, FreeList_t>::dict_census_update(size_t size, bool split, bool birth){} |
859 TreeList<Chunk>* nd = find_list(size); |
872 |
|
873 #ifndef SERIALGC |
|
874 template <> |
|
875 void BinaryTreeDictionary<FreeChunk, AdaptiveFreeList>::dict_census_update(size_t size, bool split, bool birth){ |
|
876 TreeList<FreeChunk, AdaptiveFreeList>* nd = find_list(size); |
860 if (nd) { |
877 if (nd) { |
861 if (split) { |
878 if (split) { |
862 if (birth) { |
879 if (birth) { |
863 nd->increment_split_births(); |
880 nd->increment_split_births(); |
864 nd->increment_surplus(); |
881 nd->increment_surplus(); |
880 // This is a death where the appropriate list is now |
897 // This is a death where the appropriate list is now |
881 // empty and has been removed from the list. |
898 // empty and has been removed from the list. |
882 // This is a birth associated with a LinAB. The chunk |
899 // This is a birth associated with a LinAB. The chunk |
883 // for the LinAB is not in the dictionary. |
900 // for the LinAB is not in the dictionary. |
884 } |
901 } |
885 |
902 #endif // SERIALGC |
886 template <class Chunk> |
903 |
887 bool BinaryTreeDictionary<Chunk>::coal_dict_over_populated(size_t size) { |
904 template <class Chunk_t, template <class> class FreeList_t> |
|
905 bool BinaryTreeDictionary<Chunk_t, FreeList_t>::coal_dict_over_populated(size_t size) { |
|
906 // For the general type of freelists, encourage coalescing by |
|
907 // returning true. |
|
908 return true; |
|
909 } |
|
910 |
|
911 #ifndef SERIALGC |
|
912 template <> |
|
913 bool BinaryTreeDictionary<FreeChunk, AdaptiveFreeList>::coal_dict_over_populated(size_t size) { |
888 if (FLSAlwaysCoalesceLarge) return true; |
914 if (FLSAlwaysCoalesceLarge) return true; |
889 |
915 |
890 TreeList<Chunk>* list_of_size = find_list(size); |
916 TreeList<FreeChunk, AdaptiveFreeList>* list_of_size = find_list(size); |
891 // None of requested size implies overpopulated. |
917 // None of requested size implies overpopulated. |
892 return list_of_size == NULL || list_of_size->coal_desired() <= 0 || |
918 return list_of_size == NULL || list_of_size->coal_desired() <= 0 || |
893 list_of_size->count() > list_of_size->coal_desired(); |
919 list_of_size->count() > list_of_size->coal_desired(); |
894 } |
920 } |
|
921 #endif // SERIALGC |
895 |
922 |
896 // Closures for walking the binary tree. |
923 // Closures for walking the binary tree. |
897 // do_list() walks the free list in a node applying the closure |
924 // do_list() walks the free list in a node applying the closure |
898 // to each free chunk in the list |
925 // to each free chunk in the list |
899 // do_tree() walks the nodes in the binary tree applying do_list() |
926 // do_tree() walks the nodes in the binary tree applying do_list() |
900 // to each list at each node. |
927 // to each list at each node. |
901 |
928 |
902 template <class Chunk> |
929 template <class Chunk_t, template <class> class FreeList_t> |
903 class TreeCensusClosure : public StackObj { |
930 class TreeCensusClosure : public StackObj { |
904 protected: |
931 protected: |
905 virtual void do_list(FreeList<Chunk>* fl) = 0; |
932 virtual void do_list(FreeList_t<Chunk_t>* fl) = 0; |
906 public: |
933 public: |
907 virtual void do_tree(TreeList<Chunk>* tl) = 0; |
934 virtual void do_tree(TreeList<Chunk_t, FreeList_t>* tl) = 0; |
908 }; |
935 }; |
909 |
936 |
910 template <class Chunk> |
937 template <class Chunk_t, template <class> class FreeList_t> |
911 class AscendTreeCensusClosure : public TreeCensusClosure<Chunk> { |
938 class AscendTreeCensusClosure : public TreeCensusClosure<Chunk_t, FreeList_t> { |
912 using TreeCensusClosure<Chunk>::do_list; |
|
913 public: |
939 public: |
914 void do_tree(TreeList<Chunk>* tl) { |
940 void do_tree(TreeList<Chunk_t, FreeList_t>* tl) { |
915 if (tl != NULL) { |
941 if (tl != NULL) { |
916 do_tree(tl->left()); |
942 do_tree(tl->left()); |
917 do_list(tl); |
943 do_list(tl); |
918 do_tree(tl->right()); |
944 do_tree(tl->right()); |
919 } |
945 } |
920 } |
946 } |
921 }; |
947 }; |
922 |
948 |
923 template <class Chunk> |
949 template <class Chunk_t, template <class> class FreeList_t> |
924 class DescendTreeCensusClosure : public TreeCensusClosure<Chunk> { |
950 class DescendTreeCensusClosure : public TreeCensusClosure<Chunk_t, FreeList_t> { |
925 using TreeCensusClosure<Chunk>::do_list; |
|
926 public: |
951 public: |
927 void do_tree(TreeList<Chunk>* tl) { |
952 void do_tree(TreeList<Chunk_t, FreeList_t>* tl) { |
928 if (tl != NULL) { |
953 if (tl != NULL) { |
929 do_tree(tl->right()); |
954 do_tree(tl->right()); |
930 do_list(tl); |
955 do_list(tl); |
931 do_tree(tl->left()); |
956 do_tree(tl->left()); |
932 } |
957 } |
933 } |
958 } |
934 }; |
959 }; |
935 |
960 |
936 // For each list in the tree, calculate the desired, desired |
961 // For each list in the tree, calculate the desired, desired |
937 // coalesce, count before sweep, and surplus before sweep. |
962 // coalesce, count before sweep, and surplus before sweep. |
938 template <class Chunk> |
963 template <class Chunk_t, template <class> class FreeList_t> |
939 class BeginSweepClosure : public AscendTreeCensusClosure<Chunk> { |
964 class BeginSweepClosure : public AscendTreeCensusClosure<Chunk_t, FreeList_t> { |
940 double _percentage; |
965 double _percentage; |
941 float _inter_sweep_current; |
966 float _inter_sweep_current; |
942 float _inter_sweep_estimate; |
967 float _inter_sweep_estimate; |
943 float _intra_sweep_estimate; |
968 float _intra_sweep_estimate; |
944 |
969 |
1001 } |
1029 } |
1002 }; |
1030 }; |
1003 |
1031 |
1004 // Searches the tree for a chunk that ends at the |
1032 // Searches the tree for a chunk that ends at the |
1005 // specified address. |
1033 // specified address. |
1006 template <class Chunk> |
1034 template <class Chunk_t, template <class> class FreeList_t> |
1007 class EndTreeSearchClosure : public DescendTreeSearchClosure<Chunk> { |
1035 class EndTreeSearchClosure : public DescendTreeSearchClosure<Chunk_t, FreeList_t> { |
1008 HeapWord* _target; |
1036 HeapWord* _target; |
1009 Chunk* _found; |
1037 Chunk_t* _found; |
1010 |
1038 |
1011 public: |
1039 public: |
1012 EndTreeSearchClosure(HeapWord* target) : _target(target), _found(NULL) {} |
1040 EndTreeSearchClosure(HeapWord* target) : _target(target), _found(NULL) {} |
1013 bool do_list(FreeList<Chunk>* fl) { |
1041 bool do_list(FreeList_t<Chunk_t>* fl) { |
1014 Chunk* item = fl->head(); |
1042 Chunk_t* item = fl->head(); |
1015 while (item != NULL) { |
1043 while (item != NULL) { |
1016 if (item->end() == _target) { |
1044 if (item->end() == (uintptr_t*) _target) { |
1017 _found = item; |
1045 _found = item; |
1018 return true; |
1046 return true; |
1019 } |
1047 } |
1020 item = item->next(); |
1048 item = item->next(); |
1021 } |
1049 } |
1022 return false; |
1050 return false; |
1023 } |
1051 } |
1024 Chunk* found() { return _found; } |
1052 Chunk_t* found() { return _found; } |
1025 }; |
1053 }; |
1026 |
1054 |
1027 template <class Chunk> |
1055 template <class Chunk_t, template <class> class FreeList_t> |
1028 Chunk* BinaryTreeDictionary<Chunk>::find_chunk_ends_at(HeapWord* target) const { |
1056 Chunk_t* BinaryTreeDictionary<Chunk_t, FreeList_t>::find_chunk_ends_at(HeapWord* target) const { |
1029 EndTreeSearchClosure<Chunk> etsc(target); |
1057 EndTreeSearchClosure<Chunk_t, FreeList_t> etsc(target); |
1030 bool found_target = etsc.do_tree(root()); |
1058 bool found_target = etsc.do_tree(root()); |
1031 assert(found_target || etsc.found() == NULL, "Consistency check"); |
1059 assert(found_target || etsc.found() == NULL, "Consistency check"); |
1032 assert(!found_target || etsc.found() != NULL, "Consistency check"); |
1060 assert(!found_target || etsc.found() != NULL, "Consistency check"); |
1033 return etsc.found(); |
1061 return etsc.found(); |
1034 } |
1062 } |
1035 |
1063 |
1036 template <class Chunk> |
1064 template <class Chunk_t, template <class> class FreeList_t> |
1037 void BinaryTreeDictionary<Chunk>::begin_sweep_dict_census(double coalSurplusPercent, |
1065 void BinaryTreeDictionary<Chunk_t, FreeList_t>::begin_sweep_dict_census(double coalSurplusPercent, |
1038 float inter_sweep_current, float inter_sweep_estimate, float intra_sweep_estimate) { |
1066 float inter_sweep_current, float inter_sweep_estimate, float intra_sweep_estimate) { |
1039 BeginSweepClosure<Chunk> bsc(coalSurplusPercent, inter_sweep_current, |
1067 BeginSweepClosure<Chunk_t, FreeList_t> bsc(coalSurplusPercent, inter_sweep_current, |
1040 inter_sweep_estimate, |
1068 inter_sweep_estimate, |
1041 intra_sweep_estimate); |
1069 intra_sweep_estimate); |
1042 bsc.do_tree(root()); |
1070 bsc.do_tree(root()); |
1043 } |
1071 } |
1044 |
1072 |
1045 // Closures and methods for calculating total bytes returned to the |
1073 // Closures and methods for calculating total bytes returned to the |
1046 // free lists in the tree. |
1074 // free lists in the tree. |
1047 #ifndef PRODUCT |
1075 #ifndef PRODUCT |
1048 template <class Chunk> |
1076 template <class Chunk_t, template <class> class FreeList_t> |
1049 class InitializeDictReturnedBytesClosure : public AscendTreeCensusClosure<Chunk> { |
1077 class InitializeDictReturnedBytesClosure : public AscendTreeCensusClosure<Chunk_t, FreeList_t> { |
1050 public: |
1078 public: |
1051 void do_list(FreeList<Chunk>* fl) { |
1079 void do_list(FreeList_t<Chunk_t>* fl) { |
1052 fl->set_returned_bytes(0); |
1080 fl->set_returned_bytes(0); |
1053 } |
1081 } |
1054 }; |
1082 }; |
1055 |
1083 |
1056 template <class Chunk> |
1084 template <class Chunk_t, template <class> class FreeList_t> |
1057 void BinaryTreeDictionary<Chunk>::initialize_dict_returned_bytes() { |
1085 void BinaryTreeDictionary<Chunk_t, FreeList_t>::initialize_dict_returned_bytes() { |
1058 InitializeDictReturnedBytesClosure<Chunk> idrb; |
1086 InitializeDictReturnedBytesClosure<Chunk_t, FreeList_t> idrb; |
1059 idrb.do_tree(root()); |
1087 idrb.do_tree(root()); |
1060 } |
1088 } |
1061 |
1089 |
1062 template <class Chunk> |
1090 template <class Chunk_t, template <class> class FreeList_t> |
1063 class ReturnedBytesClosure : public AscendTreeCensusClosure<Chunk> { |
1091 class ReturnedBytesClosure : public AscendTreeCensusClosure<Chunk_t, FreeList_t> { |
1064 size_t _dict_returned_bytes; |
1092 size_t _dict_returned_bytes; |
1065 public: |
1093 public: |
1066 ReturnedBytesClosure() { _dict_returned_bytes = 0; } |
1094 ReturnedBytesClosure() { _dict_returned_bytes = 0; } |
1067 void do_list(FreeList<Chunk>* fl) { |
1095 void do_list(FreeList_t<Chunk_t>* fl) { |
1068 _dict_returned_bytes += fl->returned_bytes(); |
1096 _dict_returned_bytes += fl->returned_bytes(); |
1069 } |
1097 } |
1070 size_t dict_returned_bytes() { return _dict_returned_bytes; } |
1098 size_t dict_returned_bytes() { return _dict_returned_bytes; } |
1071 }; |
1099 }; |
1072 |
1100 |
1073 template <class Chunk> |
1101 template <class Chunk_t, template <class> class FreeList_t> |
1074 size_t BinaryTreeDictionary<Chunk>::sum_dict_returned_bytes() { |
1102 size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::sum_dict_returned_bytes() { |
1075 ReturnedBytesClosure<Chunk> rbc; |
1103 ReturnedBytesClosure<Chunk_t, FreeList_t> rbc; |
1076 rbc.do_tree(root()); |
1104 rbc.do_tree(root()); |
1077 |
1105 |
1078 return rbc.dict_returned_bytes(); |
1106 return rbc.dict_returned_bytes(); |
1079 } |
1107 } |
1080 |
1108 |
1081 // Count the number of entries in the tree. |
1109 // Count the number of entries in the tree. |
1082 template <class Chunk> |
1110 template <class Chunk_t, template <class> class FreeList_t> |
1083 class treeCountClosure : public DescendTreeCensusClosure<Chunk> { |
1111 class treeCountClosure : public DescendTreeCensusClosure<Chunk_t, FreeList_t> { |
1084 public: |
1112 public: |
1085 uint count; |
1113 uint count; |
1086 treeCountClosure(uint c) { count = c; } |
1114 treeCountClosure(uint c) { count = c; } |
1087 void do_list(FreeList<Chunk>* fl) { |
1115 void do_list(FreeList_t<Chunk_t>* fl) { |
1088 count++; |
1116 count++; |
1089 } |
1117 } |
1090 }; |
1118 }; |
1091 |
1119 |
1092 template <class Chunk> |
1120 template <class Chunk_t, template <class> class FreeList_t> |
1093 size_t BinaryTreeDictionary<Chunk>::total_count() { |
1121 size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::total_count() { |
1094 treeCountClosure<Chunk> ctc(0); |
1122 treeCountClosure<Chunk_t, FreeList_t> ctc(0); |
1095 ctc.do_tree(root()); |
1123 ctc.do_tree(root()); |
1096 return ctc.count; |
1124 return ctc.count; |
1097 } |
1125 } |
1098 #endif // PRODUCT |
1126 #endif // PRODUCT |
1099 |
1127 |
1100 // Calculate surpluses for the lists in the tree. |
1128 // Calculate surpluses for the lists in the tree. |
1101 template <class Chunk> |
1129 template <class Chunk_t, template <class> class FreeList_t> |
1102 class setTreeSurplusClosure : public AscendTreeCensusClosure<Chunk> { |
1130 class setTreeSurplusClosure : public AscendTreeCensusClosure<Chunk_t, FreeList_t> { |
1103 double percentage; |
1131 double percentage; |
1104 public: |
1132 public: |
1105 setTreeSurplusClosure(double v) { percentage = v; } |
1133 setTreeSurplusClosure(double v) { percentage = v; } |
1106 void do_list(FreeList<Chunk>* fl) { |
1134 void do_list(FreeList<Chunk_t>* fl) {} |
|
1135 |
|
1136 #ifndef SERIALGC |
|
1137 void do_list(AdaptiveFreeList<Chunk_t>* fl) { |
1107 double splitSurplusPercent = percentage; |
1138 double splitSurplusPercent = percentage; |
1108 fl->set_surplus(fl->count() - |
1139 fl->set_surplus(fl->count() - |
1109 (ssize_t)((double)fl->desired() * splitSurplusPercent)); |
1140 (ssize_t)((double)fl->desired() * splitSurplusPercent)); |
1110 } |
1141 } |
1111 }; |
1142 #endif // SERIALGC |
1112 |
1143 }; |
1113 template <class Chunk> |
1144 |
1114 void BinaryTreeDictionary<Chunk>::set_tree_surplus(double splitSurplusPercent) { |
1145 template <class Chunk_t, template <class> class FreeList_t> |
1115 setTreeSurplusClosure<Chunk> sts(splitSurplusPercent); |
1146 void BinaryTreeDictionary<Chunk_t, FreeList_t>::set_tree_surplus(double splitSurplusPercent) { |
|
1147 setTreeSurplusClosure<Chunk_t, FreeList_t> sts(splitSurplusPercent); |
1116 sts.do_tree(root()); |
1148 sts.do_tree(root()); |
1117 } |
1149 } |
1118 |
1150 |
1119 // Set hints for the lists in the tree. |
1151 // Set hints for the lists in the tree. |
1120 template <class Chunk> |
1152 template <class Chunk_t, template <class> class FreeList_t> |
1121 class setTreeHintsClosure : public DescendTreeCensusClosure<Chunk> { |
1153 class setTreeHintsClosure : public DescendTreeCensusClosure<Chunk_t, FreeList_t> { |
1122 size_t hint; |
1154 size_t hint; |
1123 public: |
1155 public: |
1124 setTreeHintsClosure(size_t v) { hint = v; } |
1156 setTreeHintsClosure(size_t v) { hint = v; } |
1125 void do_list(FreeList<Chunk>* fl) { |
1157 void do_list(FreeList<Chunk_t>* fl) {} |
|
1158 |
|
1159 #ifndef SERIALGC |
|
1160 void do_list(AdaptiveFreeList<Chunk_t>* fl) { |
1126 fl->set_hint(hint); |
1161 fl->set_hint(hint); |
1127 assert(fl->hint() == 0 || fl->hint() > fl->size(), |
1162 assert(fl->hint() == 0 || fl->hint() > fl->size(), |
1128 "Current hint is inconsistent"); |
1163 "Current hint is inconsistent"); |
1129 if (fl->surplus() > 0) { |
1164 if (fl->surplus() > 0) { |
1130 hint = fl->size(); |
1165 hint = fl->size(); |
1131 } |
1166 } |
1132 } |
1167 } |
1133 }; |
1168 #endif // SERIALGC |
1134 |
1169 }; |
1135 template <class Chunk> |
1170 |
1136 void BinaryTreeDictionary<Chunk>::set_tree_hints(void) { |
1171 template <class Chunk_t, template <class> class FreeList_t> |
1137 setTreeHintsClosure<Chunk> sth(0); |
1172 void BinaryTreeDictionary<Chunk_t, FreeList_t>::set_tree_hints(void) { |
|
1173 setTreeHintsClosure<Chunk_t, FreeList_t> sth(0); |
1138 sth.do_tree(root()); |
1174 sth.do_tree(root()); |
1139 } |
1175 } |
1140 |
1176 |
1141 // Save count before previous sweep and splits and coalesces. |
1177 // Save count before previous sweep and splits and coalesces. |
1142 template <class Chunk> |
1178 template <class Chunk_t, template <class> class FreeList_t> |
1143 class clearTreeCensusClosure : public AscendTreeCensusClosure<Chunk> { |
1179 class clearTreeCensusClosure : public AscendTreeCensusClosure<Chunk_t, FreeList_t> { |
1144 void do_list(FreeList<Chunk>* fl) { |
1180 void do_list(FreeList<Chunk_t>* fl) {} |
|
1181 |
|
1182 #ifndef SERIALGC |
|
1183 void do_list(AdaptiveFreeList<Chunk_t>* fl) { |
1145 fl->set_prev_sweep(fl->count()); |
1184 fl->set_prev_sweep(fl->count()); |
1146 fl->set_coal_births(0); |
1185 fl->set_coal_births(0); |
1147 fl->set_coal_deaths(0); |
1186 fl->set_coal_deaths(0); |
1148 fl->set_split_births(0); |
1187 fl->set_split_births(0); |
1149 fl->set_split_deaths(0); |
1188 fl->set_split_deaths(0); |
1150 } |
1189 } |
1151 }; |
1190 #endif // SERIALGC |
1152 |
1191 }; |
1153 template <class Chunk> |
1192 |
1154 void BinaryTreeDictionary<Chunk>::clear_tree_census(void) { |
1193 template <class Chunk_t, template <class> class FreeList_t> |
1155 clearTreeCensusClosure<Chunk> ctc; |
1194 void BinaryTreeDictionary<Chunk_t, FreeList_t>::clear_tree_census(void) { |
|
1195 clearTreeCensusClosure<Chunk_t, FreeList_t> ctc; |
1156 ctc.do_tree(root()); |
1196 ctc.do_tree(root()); |
1157 } |
1197 } |
1158 |
1198 |
1159 // Do reporting and post sweep clean up. |
1199 // Do reporting and post sweep clean up. |
1160 template <class Chunk> |
1200 template <class Chunk_t, template <class> class FreeList_t> |
1161 void BinaryTreeDictionary<Chunk>::end_sweep_dict_census(double splitSurplusPercent) { |
1201 void BinaryTreeDictionary<Chunk_t, FreeList_t>::end_sweep_dict_census(double splitSurplusPercent) { |
1162 // Does walking the tree 3 times hurt? |
1202 // Does walking the tree 3 times hurt? |
1163 set_tree_surplus(splitSurplusPercent); |
1203 set_tree_surplus(splitSurplusPercent); |
1164 set_tree_hints(); |
1204 set_tree_hints(); |
1165 if (PrintGC && Verbose) { |
1205 if (PrintGC && Verbose) { |
1166 report_statistics(); |
1206 report_statistics(); |
1167 } |
1207 } |
1168 clear_tree_census(); |
1208 clear_tree_census(); |
1169 } |
1209 } |
1170 |
1210 |
1171 // Print summary statistics |
1211 // Print summary statistics |
1172 template <class Chunk> |
1212 template <class Chunk_t, template <class> class FreeList_t> |
1173 void BinaryTreeDictionary<Chunk>::report_statistics() const { |
1213 void BinaryTreeDictionary<Chunk_t, FreeList_t>::report_statistics() const { |
1174 FreeBlockDictionary<Chunk>::verify_par_locked(); |
1214 FreeBlockDictionary<Chunk_t>::verify_par_locked(); |
1175 gclog_or_tty->print("Statistics for BinaryTreeDictionary:\n" |
1215 gclog_or_tty->print("Statistics for BinaryTreeDictionary:\n" |
1176 "------------------------------------\n"); |
1216 "------------------------------------\n"); |
1177 size_t total_size = total_chunk_size(debug_only(NULL)); |
1217 size_t total_size = total_chunk_size(debug_only(NULL)); |
1178 size_t free_blocks = num_free_blocks(); |
1218 size_t free_blocks = num_free_blocks(); |
1179 gclog_or_tty->print("Total Free Space: %d\n", total_size); |
1219 gclog_or_tty->print("Total Free Space: %d\n", total_size); |
1180 gclog_or_tty->print("Max Chunk Size: %d\n", max_chunk_size()); |
1220 gclog_or_tty->print("Max Chunk Size: %d\n", max_chunk_size()); |
1181 gclog_or_tty->print("Number of Blocks: %d\n", free_blocks); |
1221 gclog_or_tty->print("Number of Blocks: %d\n", free_blocks); |
1182 if (free_blocks > 0) { |
1222 if (free_blocks > 0) { |
1183 gclog_or_tty->print("Av. Block Size: %d\n", total_size/free_blocks); |
1223 gclog_or_tty->print("Av. Block Size: %d\n", total_size/free_blocks); |
1184 } |
1224 } |
1185 gclog_or_tty->print("Tree Height: %d\n", treeHeight()); |
1225 gclog_or_tty->print("Tree Height: %d\n", tree_height()); |
1186 } |
1226 } |
1187 |
1227 |
1188 // Print census information - counts, births, deaths, etc. |
1228 // Print census information - counts, births, deaths, etc. |
1189 // for each list in the tree. Also print some summary |
1229 // for each list in the tree. Also print some summary |
1190 // information. |
1230 // information. |
1191 template <class Chunk> |
1231 template <class Chunk_t, template <class> class FreeList_t> |
1192 class PrintTreeCensusClosure : public AscendTreeCensusClosure<Chunk> { |
1232 class PrintTreeCensusClosure : public AscendTreeCensusClosure<Chunk_t, FreeList_t> { |
1193 int _print_line; |
1233 int _print_line; |
1194 size_t _total_free; |
1234 size_t _total_free; |
1195 FreeList<Chunk> _total; |
1235 FreeList_t<Chunk_t> _total; |
1196 |
1236 |
1197 public: |
1237 public: |
1198 PrintTreeCensusClosure() { |
1238 PrintTreeCensusClosure() { |
1199 _print_line = 0; |
1239 _print_line = 0; |
1200 _total_free = 0; |
1240 _total_free = 0; |
1201 } |
1241 } |
1202 FreeList<Chunk>* total() { return &_total; } |
1242 FreeList_t<Chunk_t>* total() { return &_total; } |
1203 size_t total_free() { return _total_free; } |
1243 size_t total_free() { return _total_free; } |
1204 void do_list(FreeList<Chunk>* fl) { |
1244 void do_list(FreeList<Chunk_t>* fl) { |
1205 if (++_print_line >= 40) { |
1245 if (++_print_line >= 40) { |
1206 FreeList<Chunk>::print_labels_on(gclog_or_tty, "size"); |
1246 FreeList_t<Chunk_t>::print_labels_on(gclog_or_tty, "size"); |
1207 _print_line = 0; |
1247 _print_line = 0; |
1208 } |
1248 } |
1209 fl->print_on(gclog_or_tty); |
1249 fl->print_on(gclog_or_tty); |
1210 _total_free += fl->count() * fl->size() ; |
1250 _total_free += fl->count() * fl->size() ; |
1211 total()->set_count( total()->count() + fl->count() ); |
1251 total()->set_count( total()->count() + fl->count() ); |
1212 total()->set_bfr_surp( total()->bfr_surp() + fl->bfr_surp() ); |
1252 } |
|
1253 |
|
1254 #ifndef SERIALGC |
|
1255 void do_list(AdaptiveFreeList<Chunk_t>* fl) { |
|
1256 if (++_print_line >= 40) { |
|
1257 FreeList_t<Chunk_t>::print_labels_on(gclog_or_tty, "size"); |
|
1258 _print_line = 0; |
|
1259 } |
|
1260 fl->print_on(gclog_or_tty); |
|
1261 _total_free += fl->count() * fl->size() ; |
|
1262 total()->set_count( total()->count() + fl->count() ); |
|
1263 total()->set_bfr_surp( total()->bfr_surp() + fl->bfr_surp() ); |
1213 total()->set_surplus( total()->split_deaths() + fl->surplus() ); |
1264 total()->set_surplus( total()->split_deaths() + fl->surplus() ); |
1214 total()->set_desired( total()->desired() + fl->desired() ); |
1265 total()->set_desired( total()->desired() + fl->desired() ); |
1215 total()->set_prev_sweep( total()->prev_sweep() + fl->prev_sweep() ); |
1266 total()->set_prev_sweep( total()->prev_sweep() + fl->prev_sweep() ); |
1216 total()->set_before_sweep(total()->before_sweep() + fl->before_sweep()); |
1267 total()->set_before_sweep(total()->before_sweep() + fl->before_sweep()); |
1217 total()->set_coal_births( total()->coal_births() + fl->coal_births() ); |
1268 total()->set_coal_births( total()->coal_births() + fl->coal_births() ); |
1218 total()->set_coal_deaths( total()->coal_deaths() + fl->coal_deaths() ); |
1269 total()->set_coal_deaths( total()->coal_deaths() + fl->coal_deaths() ); |
1219 total()->set_split_births(total()->split_births() + fl->split_births()); |
1270 total()->set_split_births(total()->split_births() + fl->split_births()); |
1220 total()->set_split_deaths(total()->split_deaths() + fl->split_deaths()); |
1271 total()->set_split_deaths(total()->split_deaths() + fl->split_deaths()); |
1221 } |
1272 } |
1222 }; |
1273 #endif // SERIALGC |
1223 |
1274 }; |
1224 template <class Chunk> |
1275 |
1225 void BinaryTreeDictionary<Chunk>::print_dict_census(void) const { |
1276 template <class Chunk_t, template <class> class FreeList_t> |
|
1277 void BinaryTreeDictionary<Chunk_t, FreeList_t>::print_dict_census(void) const { |
1226 |
1278 |
1227 gclog_or_tty->print("\nBinaryTree\n"); |
1279 gclog_or_tty->print("\nBinaryTree\n"); |
1228 FreeList<Chunk>::print_labels_on(gclog_or_tty, "size"); |
1280 FreeList_t<Chunk_t>::print_labels_on(gclog_or_tty, "size"); |
1229 PrintTreeCensusClosure<Chunk> ptc; |
1281 PrintTreeCensusClosure<Chunk_t, FreeList_t> ptc; |
1230 ptc.do_tree(root()); |
1282 ptc.do_tree(root()); |
1231 |
1283 |
1232 FreeList<Chunk>* total = ptc.total(); |
1284 FreeList_t<Chunk_t>* total = ptc.total(); |
1233 FreeList<Chunk>::print_labels_on(gclog_or_tty, " "); |
1285 FreeList_t<Chunk_t>::print_labels_on(gclog_or_tty, " "); |
|
1286 } |
|
1287 |
|
1288 #ifndef SERIALGC |
|
1289 template <> |
|
1290 void BinaryTreeDictionary<FreeChunk, AdaptiveFreeList>::print_dict_census(void) const { |
|
1291 |
|
1292 gclog_or_tty->print("\nBinaryTree\n"); |
|
1293 AdaptiveFreeList<FreeChunk>::print_labels_on(gclog_or_tty, "size"); |
|
1294 PrintTreeCensusClosure<FreeChunk, AdaptiveFreeList> ptc; |
|
1295 ptc.do_tree(root()); |
|
1296 |
|
1297 AdaptiveFreeList<FreeChunk>* total = ptc.total(); |
|
1298 AdaptiveFreeList<FreeChunk>::print_labels_on(gclog_or_tty, " "); |
1234 total->print_on(gclog_or_tty, "TOTAL\t"); |
1299 total->print_on(gclog_or_tty, "TOTAL\t"); |
1235 gclog_or_tty->print( |
1300 gclog_or_tty->print( |
1236 "total_free(words): " SIZE_FORMAT_W(16) |
1301 "total_free(words): " SIZE_FORMAT_W(16) |
1237 " growth: %8.5f deficit: %8.5f\n", |
1302 " growth: %8.5f deficit: %8.5f\n", |
1238 ptc.total_free(), |
1303 ptc.total_free(), |
1240 - total->split_deaths() - total->coal_deaths()) |
1305 - total->split_deaths() - total->coal_deaths()) |
1241 /(total->prev_sweep() != 0 ? (double)total->prev_sweep() : 1.0), |
1306 /(total->prev_sweep() != 0 ? (double)total->prev_sweep() : 1.0), |
1242 (double)(total->desired() - total->count()) |
1307 (double)(total->desired() - total->count()) |
1243 /(total->desired() != 0 ? (double)total->desired() : 1.0)); |
1308 /(total->desired() != 0 ? (double)total->desired() : 1.0)); |
1244 } |
1309 } |
1245 |
1310 #endif // SERIALGC |
1246 template <class Chunk> |
1311 |
1247 class PrintFreeListsClosure : public AscendTreeCensusClosure<Chunk> { |
1312 template <class Chunk_t, template <class> class FreeList_t> |
|
1313 class PrintFreeListsClosure : public AscendTreeCensusClosure<Chunk_t, FreeList_t> { |
1248 outputStream* _st; |
1314 outputStream* _st; |
1249 int _print_line; |
1315 int _print_line; |
1250 |
1316 |
1251 public: |
1317 public: |
1252 PrintFreeListsClosure(outputStream* st) { |
1318 PrintFreeListsClosure(outputStream* st) { |
1253 _st = st; |
1319 _st = st; |
1254 _print_line = 0; |
1320 _print_line = 0; |
1255 } |
1321 } |
1256 void do_list(FreeList<Chunk>* fl) { |
1322 void do_list(FreeList_t<Chunk_t>* fl) { |
1257 if (++_print_line >= 40) { |
1323 if (++_print_line >= 40) { |
1258 FreeList<Chunk>::print_labels_on(_st, "size"); |
1324 FreeList_t<Chunk_t>::print_labels_on(_st, "size"); |
1259 _print_line = 0; |
1325 _print_line = 0; |
1260 } |
1326 } |
1261 fl->print_on(gclog_or_tty); |
1327 fl->print_on(gclog_or_tty); |
1262 size_t sz = fl->size(); |
1328 size_t sz = fl->size(); |
1263 for (Chunk* fc = fl->head(); fc != NULL; |
1329 for (Chunk_t* fc = fl->head(); fc != NULL; |
1264 fc = fc->next()) { |
1330 fc = fc->next()) { |
1265 _st->print_cr("\t[" PTR_FORMAT "," PTR_FORMAT ") %s", |
1331 _st->print_cr("\t[" PTR_FORMAT "," PTR_FORMAT ") %s", |
1266 fc, (HeapWord*)fc + sz, |
1332 fc, (HeapWord*)fc + sz, |
1267 fc->cantCoalesce() ? "\t CC" : ""); |
1333 fc->cantCoalesce() ? "\t CC" : ""); |
1268 } |
1334 } |
1269 } |
1335 } |
1270 }; |
1336 }; |
1271 |
1337 |
1272 template <class Chunk> |
1338 template <class Chunk_t, template <class> class FreeList_t> |
1273 void BinaryTreeDictionary<Chunk>::print_free_lists(outputStream* st) const { |
1339 void BinaryTreeDictionary<Chunk_t, FreeList_t>::print_free_lists(outputStream* st) const { |
1274 |
1340 |
1275 FreeList<Chunk>::print_labels_on(st, "size"); |
1341 FreeList_t<Chunk_t>::print_labels_on(st, "size"); |
1276 PrintFreeListsClosure<Chunk> pflc(st); |
1342 PrintFreeListsClosure<Chunk_t, FreeList_t> pflc(st); |
1277 pflc.do_tree(root()); |
1343 pflc.do_tree(root()); |
1278 } |
1344 } |
1279 |
1345 |
1280 // Verify the following tree invariants: |
1346 // Verify the following tree invariants: |
1281 // . _root has no parent |
1347 // . _root has no parent |
1282 // . parent and child point to each other |
1348 // . parent and child point to each other |
1283 // . each node's key correctly related to that of its child(ren) |
1349 // . each node's key correctly related to that of its child(ren) |
1284 template <class Chunk> |
1350 template <class Chunk_t, template <class> class FreeList_t> |
1285 void BinaryTreeDictionary<Chunk>::verify_tree() const { |
1351 void BinaryTreeDictionary<Chunk_t, FreeList_t>::verify_tree() const { |
1286 guarantee(root() == NULL || total_free_blocks() == 0 || |
1352 guarantee(root() == NULL || total_free_blocks() == 0 || |
1287 total_size() != 0, "_total_size should't be 0?"); |
1353 total_size() != 0, "_total_size should't be 0?"); |
1288 guarantee(root() == NULL || root()->parent() == NULL, "_root shouldn't have parent"); |
1354 guarantee(root() == NULL || root()->parent() == NULL, "_root shouldn't have parent"); |
1289 verify_tree_helper(root()); |
1355 verify_tree_helper(root()); |
1290 } |
1356 } |
1291 |
1357 |
1292 template <class Chunk> |
1358 template <class Chunk_t, template <class> class FreeList_t> |
1293 size_t BinaryTreeDictionary<Chunk>::verify_prev_free_ptrs(TreeList<Chunk>* tl) { |
1359 size_t BinaryTreeDictionary<Chunk_t, FreeList_t>::verify_prev_free_ptrs(TreeList<Chunk_t, FreeList_t>* tl) { |
1294 size_t ct = 0; |
1360 size_t ct = 0; |
1295 for (Chunk* curFC = tl->head(); curFC != NULL; curFC = curFC->next()) { |
1361 for (Chunk_t* curFC = tl->head(); curFC != NULL; curFC = curFC->next()) { |
1296 ct++; |
1362 ct++; |
1297 assert(curFC->prev() == NULL || curFC->prev()->is_free(), |
1363 assert(curFC->prev() == NULL || curFC->prev()->is_free(), |
1298 "Chunk should be free"); |
1364 "Chunk should be free"); |
1299 } |
1365 } |
1300 return ct; |
1366 return ct; |
1301 } |
1367 } |
1302 |
1368 |
1303 // Note: this helper is recursive rather than iterative, so use with |
1369 // Note: this helper is recursive rather than iterative, so use with |
1304 // caution on very deep trees; and watch out for stack overflow errors; |
1370 // caution on very deep trees; and watch out for stack overflow errors; |
1305 // In general, to be used only for debugging. |
1371 // In general, to be used only for debugging. |
1306 template <class Chunk> |
1372 template <class Chunk_t, template <class> class FreeList_t> |
1307 void BinaryTreeDictionary<Chunk>::verify_tree_helper(TreeList<Chunk>* tl) const { |
1373 void BinaryTreeDictionary<Chunk_t, FreeList_t>::verify_tree_helper(TreeList<Chunk_t, FreeList_t>* tl) const { |
1308 if (tl == NULL) |
1374 if (tl == NULL) |
1309 return; |
1375 return; |
1310 guarantee(tl->size() != 0, "A list must has a size"); |
1376 guarantee(tl->size() != 0, "A list must has a size"); |
1311 guarantee(tl->left() == NULL || tl->left()->parent() == tl, |
1377 guarantee(tl->left() == NULL || tl->left()->parent() == tl, |
1312 "parent<-/->left"); |
1378 "parent<-/->left"); |