--- /dev/null 2019-09-04 10:58:08.784555846 -0700 +++ new/src/hotspot/share/gc/g1/g1NUMA.inline.hpp 2019-09-21 06:25:36.713961190 -0700 @@ -0,0 +1,78 @@ +/* + * 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_NUMA_INLINE_HPP +#define SHARE_VM_GC_G1_NUMA_INLINE_HPP + +#include "gc/g1/g1MemoryNodeManager.hpp" +#include "gc/g1/g1NUMA.hpp" +#include "runtime/atomic.hpp" + +inline bool G1NUMA::is_valid_numa_id(int numa_id) { + // Valid numa id should be one of active numa ids. + for (uint i = 0; i < _num_active_numa_ids; i++) { + if (_numa_ids[i] == numa_id) { + return true; + } + } + return false; +} + +inline bool G1NUMA::is_valid_numa_index(uint numa_index) const { + // Valid numa index should be less than the number of active numa ids. + return numa_index < _num_active_numa_ids; +} + +inline uint G1NUMA::num_active_numa_ids() const { + assert(_num_active_numa_ids > 0, "just checking"); + return _num_active_numa_ids; +} + +inline uint G1NUMA::next_numa_index() { + // Overflow of uint does not matter here to get numa index. + uint numa_index = Atomic::add(1u, &_next_numa_index); + return numa_index % _num_active_numa_ids; +} + +inline int G1NUMA::next_numa_id() { + return _numa_ids[next_numa_index()]; +} + +inline uint G1NUMA::index_of_numa_id(int numa_id) const { + // Don't need call is_valid_numa_id, as _numa_id_to_index_map + // may return G1MemoryNodeManager::InvalidNodeIndex. + if (numa_id >= 0 && numa_id < _len_numa_id_to_index_map) { + return _numa_id_to_index_map[numa_id]; + } + return G1MemoryNodeManager::InvalidNodeIndex; +} + +inline int G1NUMA::numa_id_of_index(uint numa_index) const { + if (is_valid_numa_index(numa_index)) { + return _numa_ids[numa_index]; + } + return os::InvalidId; +} + +#endif // SHARE_VM_GC_G1_NUMA_INLINE_HPP