--- old/src/share/vm/gc/g1/dirtyCardQueue.cpp 2016-07-21 12:32:30.043639238 +0200 +++ new/src/share/vm/gc/g1/dirtyCardQueue.cpp 2016-07-21 12:32:29.955636589 +0200 @@ -122,7 +122,7 @@ // Determines how many mutator threads can process the buffers in parallel. uint DirtyCardQueueSet::num_par_ids() { - return (uint)os::processor_count(); + return (uint)os::initial_active_processor_count(); } void DirtyCardQueueSet::initialize(CardTableEntryClosure* cl, --- old/src/share/vm/gc/g1/g1ConcurrentMark.cpp 2016-07-21 12:32:30.535654048 +0200 +++ new/src/share/vm/gc/g1/g1ConcurrentMark.cpp 2016-07-21 12:32:30.446651369 +0200 @@ -416,11 +416,10 @@ double overall_cm_overhead = (double) MaxGCPauseMillis * marking_overhead / (double) GCPauseIntervalMillis; - double cpu_ratio = 1.0 / (double) os::processor_count(); + double cpu_ratio = 1.0 / os::initial_active_processor_count(); double marking_thread_num = ceil(overall_cm_overhead / cpu_ratio); double marking_task_overhead = - overall_cm_overhead / marking_thread_num * - (double) os::processor_count(); + overall_cm_overhead / marking_thread_num * os::initial_active_processor_count(); double sleep_factor = (1.0 - marking_task_overhead) / marking_task_overhead; --- old/src/share/vm/runtime/os.cpp 2016-07-21 12:32:31.055669700 +0200 +++ new/src/share/vm/runtime/os.cpp 2016-07-21 12:32:30.963666931 +0200 @@ -71,6 +71,7 @@ uintptr_t os::_serialize_page_mask = 0; long os::_rand_seed = 1; int os::_processor_count = 0; +int os::_initial_active_processor_count = 0; size_t os::_page_sizes[os::page_sizes_max]; #ifndef PRODUCT @@ -1759,6 +1760,13 @@ } #endif +void os::set_processor_count(int count) { + assert(_processor_count == 0, "Trying to set processor count twice, from %d to %d", _processor_count, count); + _processor_count = count; + _initial_active_processor_count = active_processor_count(); + log_trace(os)("Initial active processor count is %d", _initial_active_processor_count); +} + /////////////// Unit tests /////////////// #ifndef PRODUCT --- old/src/share/vm/runtime/os.hpp 2016-07-21 12:32:31.569685172 +0200 +++ new/src/share/vm/runtime/os.hpp 2016-07-21 12:32:31.478682433 +0200 @@ -235,12 +235,18 @@ static int processor_count() { return _processor_count; } - static void set_processor_count(int count) { _processor_count = count; } + static void set_processor_count(int count); // Returns the number of CPUs this process is currently allowed to run on. // Note that on some OSes this can change dynamically. static int active_processor_count(); + // At startup the number of active CPUs this process is allowed to run on. + // This value does not change dynamically. May be different to active_processor_count(). + static int initial_active_processor_count() { + return _initial_active_processor_count; + } + // Bind processes to processors. // This is a two step procedure: // first you generate a distribution of processes to processors, @@ -1012,8 +1018,9 @@ protected: - static long _rand_seed; // seed for random number generator - static int _processor_count; // number of processors + static long _rand_seed; // seed for random number generator + static int _processor_count; // number of processors + static int _initial_active_processor_count; // number of active processors during initialization. static char* format_boot_path(const char* format_string, const char* home, --- old/src/share/vm/runtime/vm_version.cpp 2016-07-21 12:32:32.068700193 +0200 +++ new/src/share/vm/runtime/vm_version.cpp 2016-07-21 12:32:31.979697514 +0200 @@ -295,7 +295,7 @@ // processor after the first 8. For example, on a 72 cpu machine // and a chosen fraction of 5/8 // use 8 + (72 - 8) * (5/8) == 48 worker threads. - unsigned int ncpus = (unsigned int) os::active_processor_count(); + unsigned int ncpus = (unsigned int) os::initial_active_processor_count(); threads = (ncpus <= switch_pt) ? ncpus : (switch_pt + ((ncpus - switch_pt) * num) / den);