< prev index next >
src/hotspot/share/gc/g1/heapRegionManager.cpp
Print this page
rev 56448 : imported patch 8220310.mut.0
rev 56449 : imported patch 8220310.mut.1_thomas
rev 56451 : imported patch 8220310.mut.1-3_kim
rev 56452 : imported patch 8220310.mut.2-stefan
rev 56453 : imported patch 8220310.mut.2-kim
rev 56454 : [mq]: 8220310.mut.2-evensplit
*** 28,37 ****
--- 28,38 ----
#include "gc/g1/g1ConcurrentRefine.hpp"
#include "gc/g1/heapRegion.hpp"
#include "gc/g1/heapRegionManager.inline.hpp"
#include "gc/g1/heapRegionSet.inline.hpp"
#include "gc/g1/heterogeneousHeapRegionManager.hpp"
+ #include "logging/logStream.hpp"
#include "memory/allocation.hpp"
#include "utilities/bitMap.inline.hpp"
class MasterFreeRegionListChecker : public HeapRegionSetChecker {
public:
*** 101,110 ****
--- 102,156 ----
bool HeapRegionManager::is_available(uint region) const {
return _available_map.at(region);
}
+ // If log is enabled, compare actual node index and the node index. If those are different
+ // return the actual node index.
+ // If log is disabled, just return the node index.
+ static uint verify_actual_node_index(HeapWord* addr, uint node_index) {
+ LogTarget(Debug, gc, heap, numa, verification) lt;
+
+ if (lt.is_enabled()) {
+ LogStream ls(lt);
+
+ uint actual_node_index = G1MemoryNodeManager::mgr()->index_of_address(addr);
+ if (node_index != actual_node_index) {
+ ls.print_cr("Heap Region (%u) has different node index. actual index=%u, index=%u",
+ G1CollectedHeap::heap()->addr_to_region(addr), actual_node_index, node_index);
+ }
+ return actual_node_index;
+ }
+ return node_index;
+ }
+
+ HeapRegion* HeapRegionManager::allocate_free_region(HeapRegionType type, uint requested_node_index) {
+ G1MemoryNodeManager* mgr = G1MemoryNodeManager::mgr();
+ HeapRegion* hr = NULL;
+ bool from_head = !type.is_young();
+
+ if (mgr->num_active_nodes() > 1 && mgr->is_valid_node_index(requested_node_index)) {
+ // Try to allocate with requested node index.
+ hr = _free_list.remove_region_with_node_index(from_head, requested_node_index, NULL);
+ }
+
+ if (hr == NULL) {
+ // If there's a single active node or we did not get a region from our requested node,
+ // try without requested node index.
+ hr = _free_list.remove_region(from_head);
+ }
+
+ if (hr != NULL) {
+ assert(hr->next() == NULL, "Single region should not have next");
+ assert(is_available(hr->hrm_index()), "Must be committed");
+
+ verify_actual_node_index(hr->bottom(), hr->node_index());
+ }
+
+ return hr;
+ }
+
#ifdef ASSERT
bool HeapRegionManager::is_free(HeapRegion* hr) const {
return _free_list.contains(hr);
}
#endif
*** 137,146 ****
--- 183,197 ----
void HeapRegionManager::uncommit_regions(uint start, size_t num_regions) {
guarantee(num_regions >= 1, "Need to specify at least one region to uncommit, tried to uncommit zero regions at %u", start);
guarantee(_num_committed >= num_regions, "pre-condition");
+ // Reset node index to distinguish with committed regions.
+ for (uint i = start; i < start + num_regions; i++) {
+ at(i)->set_node_index(G1MemoryNodeManager::InvalidNodeIndex);
+ }
+
// Print before uncommitting.
if (G1CollectedHeap::heap()->hr_printer()->is_active()) {
for (uint i = start; i < start + num_regions; i++) {
HeapRegion* hr = at(i);
G1CollectedHeap::heap()->hr_printer()->uncommit(hr);
*** 160,169 ****
--- 211,248 ----
_cardtable_mapper->uncommit_regions(start, num_regions);
_card_counts_mapper->uncommit_regions(start, num_regions);
}
+ static void print_node_id_of_regions(uint start, uint num_regions) {
+ LogTarget(Trace, gc, heap, numa) lt;
+
+ if (lt.is_enabled()) {
+ LogStream ls(lt);
+
+ // Below logs are checked by TestG1NUMATouchRegions.java.
+ ls.print_cr("Numa id of heap regions from %u to %u", start, start + num_regions - 1);
+ ls.print_cr("Heap Region# : numa id of pages");
+
+ for (uint i = start; i < start + num_regions; i++) {
+ ls.print_cr("%6u : %02u", i, G1CollectedHeap::heap()->region_at(i)->node_index());
+ }
+ }
+ }
+
+ // Set node index of the given HeapRegion.
+ // If AlwaysPreTouch is enabled, set with actual node index.
+ // If it is disabled, set with preferred node index which is already decided.
+ static void set_heapregion_node_index(HeapRegion* hr) {
+ uint node_index = G1MemoryNodeManager::mgr()->preferred_index_for_address(hr->bottom());
+ if(AlwaysPreTouch) {
+ // If we already pretouched, we can check actual node index here.
+ node_index = verify_actual_node_index(hr->bottom(), node_index);
+ }
+ hr->set_node_index(node_index);
+ }
+
void HeapRegionManager::make_regions_available(uint start, uint num_regions, WorkGang* pretouch_gang) {
guarantee(num_regions > 0, "No point in calling this for zero regions");
commit_regions(start, num_regions, pretouch_gang);
for (uint i = start; i < start + num_regions; i++) {
if (_regions.get_by_index(i) == NULL) {
*** 184,195 ****
--- 263,279 ----
}
HeapWord* bottom = G1CollectedHeap::heap()->bottom_addr_for_region(i);
MemRegion mr(bottom, bottom + HeapRegion::GrainWords);
hr->initialize(mr);
+ // Set node index of the heap region after initialization but before inserting
+ // to free list.
+ set_heapregion_node_index(hr);
insert_into_free_list(at(i));
}
+
+ print_node_id_of_regions(start, num_regions);
}
MemoryUsage HeapRegionManager::get_auxiliary_data_memory_usage() const {
size_t used_sz =
_prev_bitmap_mapper->committed_size() +
*** 233,242 ****
--- 317,357 ----
verify_optional();
return expanded;
}
+ uint HeapRegionManager::expand_on_preferred_node(uint preferred_index) {
+ uint expand_candidate = UINT_MAX;
+ for (uint i = 0; i < max_length(); i++) {
+ if (is_available(i)) {
+ // Already in use continue
+ continue;
+ }
+ // Always save the candidate so we can expand later on.
+ expand_candidate = i;
+ if (is_on_preferred_index(expand_candidate, preferred_index)) {
+ // We have found a candidate on the preffered node, break.
+ break;
+ }
+ }
+
+ if (expand_candidate == UINT_MAX) {
+ // No regions left, expand failed.
+ return 0;
+ }
+
+ make_regions_available(expand_candidate, 1, NULL);
+ return 1;
+ }
+
+ bool HeapRegionManager::is_on_preferred_index(uint region_index, uint preferred_node_index) {
+ uint region_node_index = G1MemoryNodeManager::mgr()->preferred_index_for_address(
+ G1CollectedHeap::heap()->bottom_addr_for_region(region_index));
+ return region_node_index == preferred_node_index ||
+ preferred_node_index == G1MemoryNodeManager::AnyNodeIndex;
+ }
+
uint HeapRegionManager::find_contiguous(size_t num, bool empty_only) {
uint found = 0;
size_t length_found = 0;
uint cur = 0;
< prev index next >