27 28 #include "memory/allocation.hpp" 29 #include "runtime/os.hpp" 30 31 class HeapRegion; 32 33 class G1NUMA: public CHeapObj<mtGC> { 34 // Mapping of available node ids to 0-based index which can be used for 35 // fast resource management. I.e. for every node id provides a unique value in 36 // the range from [0, {# of nodes-1}]. 37 // For invalid node id, return UnknownNodeIndex. 38 uint* _node_id_to_index_map; 39 // Length of _num_active_node_ids_id to index map. 40 int _len_node_id_to_index_map; 41 42 // Current active node ids. 43 int* _node_ids; 44 // Total number of node ids. 45 uint _num_active_node_ids; 46 47 // Base address of Java heap 48 void* _base_address; 49 // HeapRegion size 50 size_t _region_size; 51 // Necessary when touching memory. 52 size_t _page_size; 53 54 void* base_address() const; 55 size_t region_size() const; 56 size_t page_size() const; 57 58 // Returns node index of the given node id. 59 // Precondition: node_id is an active node id. 60 inline uint index_of_node_id(int node_id) const; 61 62 // Creates node id and node index mapping table of _node_id_to_index_map. 63 void init_node_id_to_index_map(const int* node_ids, uint num_node_ids); 64 65 static G1NUMA* _inst; 66 67 G1NUMA(); 68 void initialize(bool use_numa); 69 void initialize_without_numa(); 70 71 public: 72 static const uint UnknownNodeIndex = UINT_MAX; 73 static const uint AnyNodeIndex = UnknownNodeIndex - 1; 74 75 static G1NUMA* numa() { return _inst; } 76 77 static G1NUMA* create(); 78 79 ~G1NUMA(); 80 81 // Set base address of heap, heap region size and page size after those values 82 // are determined at G1CollectedHeap::initialize(). 83 void set_region_info(void* base_address, size_t region_size, size_t page_size); 84 85 // Print current active memory node count. 86 uint num_active_nodes() const; 87 88 bool is_enabled() const; 89 90 int numa_id(int index) const; 91 92 // Returns memory node ids 93 const int* node_ids() const; 94 95 // Returns node index of current calling thread. 96 uint index_of_current_thread() const; 97 98 // Returns the preferred index for the given HeapRegion index. 99 // This assumes that HeapRegions are evenly spit, so we can decide preferred index 100 // with the given HeapRegion index. 101 // Result is less than num_active_nodes(). 102 uint preferred_node_index_for_index(uint region_index) const; 103 104 // Retrieve node index of the given address. 105 // Result is less than num_active_nodes() or is UnknownNodeIndex. 106 // Precondition: address is in reserved range for heap. 107 uint index_of_address(HeapWord* address) const; 108 109 // If AlwaysPreTouch is enabled, return actual node index via system call. 110 // If disabled, return preferred node index of the given heap region. 111 uint index_for_region(HeapRegion* hr) const; 112 113 // Request the given memory area to be located at the given node index. 114 void request_memory_on_node(size_t start_page, size_t size_in_pages, uint region_index); 115 116 // Returns maximum search depth which is used to limit heap region search iterations. 117 // The number of active nodes, page size and heap region size are considered. 118 uint max_search_depth() const; 119 }; 120 121 #endif // SHARE_VM_GC_G1_NUMA_HPP | 27 28 #include "memory/allocation.hpp" 29 #include "runtime/os.hpp" 30 31 class HeapRegion; 32 33 class G1NUMA: public CHeapObj<mtGC> { 34 // Mapping of available node ids to 0-based index which can be used for 35 // fast resource management. I.e. for every node id provides a unique value in 36 // the range from [0, {# of nodes-1}]. 37 // For invalid node id, return UnknownNodeIndex. 38 uint* _node_id_to_index_map; 39 // Length of _num_active_node_ids_id to index map. 40 int _len_node_id_to_index_map; 41 42 // Current active node ids. 43 int* _node_ids; 44 // Total number of node ids. 45 uint _num_active_node_ids; 46 47 // HeapRegion size 48 size_t _region_size; 49 // Necessary when touching memory. 50 size_t _page_size; 51 52 size_t region_size() const; 53 size_t page_size() const; 54 55 // Returns node index of the given node id. 56 // Precondition: node_id is an active node id. 57 inline uint index_of_node_id(int node_id) const; 58 59 // Creates node id and node index mapping table of _node_id_to_index_map. 60 void init_node_id_to_index_map(const int* node_ids, uint num_node_ids); 61 62 static G1NUMA* _inst; 63 64 G1NUMA(); 65 void initialize(bool use_numa); 66 void initialize_without_numa(); 67 68 public: 69 static const uint UnknownNodeIndex = UINT_MAX; 70 static const uint AnyNodeIndex = UnknownNodeIndex - 1; 71 72 static G1NUMA* numa() { return _inst; } 73 74 static G1NUMA* create(); 75 76 ~G1NUMA(); 77 78 // Sets heap region size and page size after those values 79 // are determined at G1CollectedHeap::initialize(). 80 void set_region_info(size_t region_size, size_t page_size); 81 82 // Returns active memory node count. 83 uint num_active_nodes() const; 84 85 bool is_enabled() const; 86 87 int numa_id(int index) const; 88 89 // Returns memory node ids 90 const int* node_ids() const; 91 92 // Returns node index of current calling thread. 93 uint index_of_current_thread() const; 94 95 // Returns the preferred index for the given HeapRegion index. 96 // This assumes that HeapRegions are evenly spit, so we can decide preferred index 97 // with the given HeapRegion index. 98 // Result is less than num_active_nodes(). 99 uint preferred_node_index_for_index(uint region_index) const; 100 101 // Retrieves node index of the given address. 102 // Result is less than num_active_nodes() or is UnknownNodeIndex. 103 // Precondition: address is in reserved range for heap. 104 uint index_of_address(HeapWord* address) const; 105 106 // If AlwaysPreTouch is enabled, return actual node index via system call. 107 // If disabled, return preferred node index of the given heap region. 108 uint index_for_region(HeapRegion* hr) const; 109 110 // Requests the given memory area to be located at the given node index. 111 void request_memory_on_node(void* aligned_address, size_t size_in_bytes, uint region_index); 112 113 // Returns maximum search depth which is used to limit heap region search iterations. 114 // The number of active nodes, page size and heap region size are considered. 115 uint max_search_depth() const; 116 }; 117 118 #endif // SHARE_VM_GC_G1_NUMA_HPP |