Path: blob/master/src/hotspot/share/gc/z/zCPU.cpp
40961 views
/*1* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include "precompiled.hpp"24#include "gc/shared/gcLogPrecious.hpp"25#include "gc/z/zCPU.inline.hpp"26#include "memory/padded.inline.hpp"27#include "runtime/os.hpp"28#include "runtime/thread.inline.hpp"29#include "utilities/debug.hpp"3031#define ZCPU_UNKNOWN_AFFINITY ((Thread*)-1)32#define ZCPU_UNKNOWN_SELF ((Thread*)-2)3334PaddedEnd<ZCPU::ZCPUAffinity>* ZCPU::_affinity = NULL;35THREAD_LOCAL Thread* ZCPU::_self = ZCPU_UNKNOWN_SELF;36THREAD_LOCAL uint32_t ZCPU::_cpu = 0;3738void ZCPU::initialize() {39assert(_affinity == NULL, "Already initialized");40const uint32_t ncpus = count();4142_affinity = PaddedArray<ZCPUAffinity, mtGC>::create_unfreeable(ncpus);4344for (uint32_t i = 0; i < ncpus; i++) {45_affinity[i]._thread = ZCPU_UNKNOWN_AFFINITY;46}4748log_info_p(gc, init)("CPUs: %u total, %u available",49os::processor_count(),50os::initial_active_processor_count());51}5253uint32_t ZCPU::id_slow() {54// Set current thread55if (_self == ZCPU_UNKNOWN_SELF) {56_self = Thread::current();57}5859// Set current CPU60_cpu = os::processor_id();6162// Update affinity table63_affinity[_cpu]._thread = _self;6465return _cpu;66}676869