On Windows, GetSystemInfo is used and dwNumberOfProcessors
from the returned SYSTEM_INFO
structure.
This can be seen from void os::win32::initialize_system_info()
and int os::active_processor_count()
in os_windows.cpp
of the OpenJDK source code.
dwNumberOfProcessors
, from the MSDN documentation says that it reports 'The number of logical processors in the current group', which means that hyperthreading will increase the number of CPUs reported.
On Linux, os::active_processor_count()
uses sysconf:
int os::active_processor_count() {
// Linux doesn't yet have a (official) notion of processor sets,
// so just return the number of online processors.
int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN);
assert(online_cpus > 0 && online_cpus <= processor_count(), "sanity check");
return online_cpus;
}
Where _SC_NPROCESSORS_ONLN
documentation says 'The number of processors currently online (available).' This is not affected by the affinity of the process, and is also affected by hyperthreading.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…