void HeapRegionSet::update_from_proxy(HeapRegionSet* proxy_set) { hrl_assert_mt_safety_ok(this); hrl_assert_mt_safety_ok(proxy_set); hrl_assert_sets_match(this, proxy_set); verify_optional(); proxy_set->verify_optional(); if (proxy_set->is_empty()) return; assert(proxy_set->length() <= _length, hrl_err_msg("[%s] proxy set length: "SIZE_FORMAT" " "should be <= length: "SIZE_FORMAT, name(), proxy_set->length(), _length)); _length -= proxy_set->length(); assert(proxy_set->region_num() <= _region_num, hrl_err_msg("[%s] proxy set region num: "SIZE_FORMAT" " "should be <= region num: "SIZE_FORMAT, name(), proxy_set->region_num(), _region_num)); _region_num -= proxy_set->region_num(); assert(proxy_set->total_used_bytes() <= _total_used_bytes, hrl_err_msg("[%s] proxy set used bytes: "SIZE_FORMAT" " "should be <= used bytes: "SIZE_FORMAT, name(), proxy_set->total_used_bytes(), _total_used_bytes)); _total_used_bytes -= proxy_set->total_used_bytes(); proxy_set->clear(); verify_optional(); proxy_set->verify_optional(); }
uint HeapRegionManager::shrink_by(uint num_regions_to_remove) { assert(length() > 0, "the region sequence should not be empty"); assert(length() <= _allocated_heapregions_length, "invariant"); assert(_allocated_heapregions_length > 0, "we should have at least one region committed"); assert(num_regions_to_remove < length(), "We should never remove all regions"); if (num_regions_to_remove == 0) { return 0; } uint removed = 0; uint cur = _allocated_heapregions_length - 1; uint idx_last_found = 0; uint num_last_found = 0; while ((removed < num_regions_to_remove) && (num_last_found = find_empty_from_idx_reverse(cur, &idx_last_found)) > 0) { uint to_remove = MIN2(num_regions_to_remove - removed, num_last_found); shrink_at(idx_last_found + num_last_found - to_remove, to_remove); cur = idx_last_found; removed += to_remove; } verify_optional(); return removed; }
inline HeapRegion* FreeRegionList::remove_region(bool from_head) { check_mt_safety(); verify_optional(); if (is_empty()) { return NULL; } assert_free_region_list(length() > 0 && _head != NULL && _tail != NULL, "invariant"); HeapRegion* hr; if (from_head) { hr = remove_from_head_impl(); } else { hr = remove_from_tail_impl(); } if (_last == hr) { _last = NULL; } // remove() will verify the region and check mt safety. remove(hr); return hr; }
void FreeRegionList::remove_starting_at(HeapRegion* first, uint num_regions) { check_mt_safety(); assert(num_regions >= 1, hrs_ext_msg(this, "pre-condition")); assert(!is_empty(), hrs_ext_msg(this, "pre-condition")); verify_optional(); DEBUG_ONLY(uint old_length = length();)
void FreeRegionList::remove_all_pending(uint target_count) { check_mt_safety(); assert(target_count > 1, hrs_ext_msg(this, "pre-condition")); assert(!is_empty(), hrs_ext_msg(this, "pre-condition")); verify_optional(); DEBUG_ONLY(uint old_length = length();)
void HeapRegionLinkedList::remove_all_pending(size_t target_count) { hrl_assert_mt_safety_ok(this); assert(target_count > 1, hrl_ext_msg(this, "pre-condition")); assert(!is_empty(), hrl_ext_msg(this, "pre-condition")); verify_optional(); DEBUG_ONLY(size_t old_length = length();)
void FreeRegionList::add_as_head_or_tail(FreeRegionList* from_list, bool as_head) { check_mt_safety(); from_list->check_mt_safety(); verify_optional(); from_list->verify_optional(); if (from_list->is_empty()) { return; } #ifdef ASSERT FreeRegionListIterator iter(from_list); while (iter.more_available()) { HeapRegion* hr = iter.get_next(); // In set_containing_set() we check that we either set the value // from NULL to non-NULL or vice versa to catch bugs. So, we have // to NULL it first before setting it to the value. hr->set_containing_set(NULL); hr->set_containing_set(this); } #endif // ASSERT if (_head == NULL) { assert(length() == 0 && _tail == NULL, hrs_ext_msg(this, "invariant")); _head = from_list->_head; _tail = from_list->_tail; } else { assert(length() > 0 && _tail != NULL, hrs_ext_msg(this, "invariant")); if (as_head) { from_list->_tail->set_next(_head); _head->set_prev(from_list->_tail); _head = from_list->_head; } else { _tail->set_next(from_list->_head); from_list->_head->set_prev(_tail); _tail = from_list->_tail; } } _count.increment(from_list->length(), from_list->total_capacity_bytes()); from_list->clear(); verify_optional(); from_list->verify_optional(); }
void HeapRegionLinkedList::remove_all() { hrl_assert_mt_safety_ok(this); verify_optional(); HeapRegion* curr = _head; while (curr != NULL) { hrl_assert_region_ok(this, curr, this); HeapRegion* next = curr->next(); curr->set_next(NULL); curr->set_containing_set(NULL); curr = next; } clear(); verify_optional(); }
void FreeRegionList::remove_all() { check_mt_safety(); verify_optional(); HeapRegion* curr = _head; while (curr != NULL) { verify_region(curr); HeapRegion* next = curr->next(); curr->set_next(NULL); curr->set_prev(NULL); curr->set_containing_set(NULL); curr = next; } clear(); verify_optional(); }
void HeapRegionLinkedList::add_as_tail(HeapRegionLinkedList* from_list) { hrl_assert_mt_safety_ok(this); hrl_assert_mt_safety_ok(from_list); verify_optional(); from_list->verify_optional(); if (from_list->is_empty()) return; #ifdef ASSERT HeapRegionLinkedListIterator iter(from_list); while (iter.more_available()) { HeapRegion* hr = iter.get_next(); // In set_containing_set() we check that we either set the value // from NULL to non-NULL or vice versa to catch bugs. So, we have // to NULL it first before setting it to the value. hr->set_containing_set(NULL); hr->set_containing_set(this); } #endif // ASSERT if (_tail != NULL) { assert(length() > 0 && _head != NULL, hrl_ext_msg(this, "invariant")); _tail->set_next(from_list->_head); } else { assert(length() == 0 && _head == NULL, hrl_ext_msg(this, "invariant")); _head = from_list->_head; } _tail = from_list->_tail; _length += from_list->length(); _region_num += from_list->region_num(); _total_used_bytes += from_list->total_used_bytes(); from_list->clear(); verify_optional(); from_list->verify_optional(); }
uint HeapRegionManager::expand_at(uint start, uint num_regions) { if (num_regions == 0) { return 0; } uint cur = start; uint idx_last_found = 0; uint num_last_found = 0; uint expanded = 0; while (expanded < num_regions && (num_last_found = find_unavailable_from_idx(cur, &idx_last_found)) > 0) { uint to_expand = MIN2(num_regions - expanded, num_last_found); make_regions_available(idx_last_found, to_expand); expanded += to_expand; cur = idx_last_found + num_last_found + 1; } verify_optional(); return expanded; }
void FreeRegionList::add_ordered(FreeRegionList* from_list) { check_mt_safety(); from_list->check_mt_safety(); verify_optional(); from_list->verify_optional(); if (from_list->is_empty()) { return; } #ifdef ASSERT FreeRegionListIterator iter(from_list); while (iter.more_available()) { HeapRegion* hr = iter.get_next(); // In set_containing_set() we check that we either set the value // from NULL to non-NULL or vice versa to catch bugs. So, we have // to NULL it first before setting it to the value. hr->set_containing_set(NULL); hr->set_containing_set(this); } #endif // ASSERT if (is_empty()) { assert(length() == 0 && _tail == NULL, hrs_ext_msg(this, "invariant")); _head = from_list->_head; _tail = from_list->_tail; } else { HeapRegion* curr_to = _head; HeapRegion* curr_from = from_list->_head; while (curr_from != NULL) { while (curr_to != NULL && curr_to->hrm_index() < curr_from->hrm_index()) { curr_to = curr_to->next(); } if (curr_to == NULL) { // The rest of the from list should be added as tail _tail->set_next(curr_from); curr_from->set_prev(_tail); curr_from = NULL; } else { HeapRegion* next_from = curr_from->next(); curr_from->set_next(curr_to); curr_from->set_prev(curr_to->prev()); if (curr_to->prev() == NULL) { _head = curr_from; } else { curr_to->prev()->set_next(curr_from); } curr_to->set_prev(curr_from); curr_from = next_from; } } if (_tail->hrm_index() < from_list->_tail->hrm_index()) { _tail = from_list->_tail; } } _count.increment(from_list->length(), from_list->total_capacity_bytes()); from_list->clear(); verify_optional(); from_list->verify_optional(); }