--- /dev/null 2019-09-30 10:03:02.736928411 -0700 +++ new/src/hotspot/share/gc/g1/g1NUMA.hpp 2019-09-30 17:13:31.936028675 -0700 @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +#ifndef SHARE_VM_GC_G1_G1NUMA_HPP +#define SHARE_VM_GC_G1_G1NUMA_HPP + +#include "runtime/globals.hpp" + +// Manages NUMA node related information. +// Provides a conversion between NUMA indices (sequential, starting +// from zero) and NUMA ids (which may not start at zero and may not be +// sequential). Indices are generally used by clients, and mapped to +// ids when dealing with the OS/hardware layer. +class G1NUMA : public CHeapObj { + // Mapping of available numa ids to some 0-based index which can be used for + // fast resource management. I.e. for every numa id provides a unique value in + // the range from [0, {# of numa nodes-1}]. + // For invalid numa id, return G1MemoryNodeManager::InvalidNodeIndex. + // So the caller need exception handling. + uint* _numa_id_to_index_map; + // Length of numa_id to index map. + int _len_numa_id_to_index_map; + + // Necessary when touching memory. + size_t _page_size; + + // Current active numa ids. + int* _numa_ids; + // Total number of numa ids. + uint _num_active_numa_ids; + + static G1NUMA* _inst; + + // Creates numa id and numa index mapping table of _numa_id_to_index_map. + void init_numa_id_to_index_map(const int* numa_ids, uint num_numa_ids); + +public: + G1NUMA() : _numa_id_to_index_map(NULL), _len_numa_id_to_index_map(0), + _page_size(0), _numa_ids(NULL), _num_active_numa_ids(0) { } + ~G1NUMA(); + + static G1NUMA* numa() { return _inst; } + + static void set_numa(G1NUMA* numa) { + guarantee(_inst == NULL, "Should be called once."); + + _inst = numa; + } + + void request_memory_on_node(address aligned_address, size_t size_in_bytes); + + bool initialize(); + + inline bool is_valid_numa_id(int numa_id); + + inline bool is_valid_numa_index(uint numa_index) const; + + inline uint num_active_numa_ids() const; + + // Returns numa index of the given numa id. + // Returns G1MemoryNodeManager::InvalidNodeIndex if the given numa id is invalid. + inline uint index_of_numa_id(int numa_id) const; + + uint index_of_current_thread() const; + + // Returns numa id of the given numa index. + inline int numa_id_of_index(uint numa_index) const; + + // Initialize with information after heap is created. + // If AlwaysPreTouch is disabled _numa_id_of_regions_table is initialized. + void set_page_size(size_t page_size); + + // Returns current active numa ids. + const int* numa_ids() const { return _numa_ids; } + + // Returns the preferred index for the given address. + // This assumes that HeapRegions are evenly spit, so we can decide preferred index + // with the given address. + uint preferred_index_for_address(HeapWord* address) const; + + // Returns numa index of the given address via system call. + uint index_of_address(HeapWord* address) const; +}; + +#endif // SHARE_VM_GC_G1_G1NUMA_HPP