JDK-8188310 : Runtime.getRuntime().availableProcessors() returns wrong value
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 8u131
  • Priority: P3
  • Status: Closed
  • Resolution: Incomplete
  • OS: linux
  • CPU: x86_64
  • Submitted: 2017-09-27
  • Updated: 2017-11-24
  • Resolved: 2017-11-24
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
Java version "1.8.0_141"
Java(TM) SE Runtime Environment (build 1.8.0_141-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.141-b15, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Red Hat Enterprise Linux Server release 6.9 (Santiago)
Linux myhost 2.6.32-696.10.1.el6.x86_64 #1 SMP  x86_64 GNU/Linux


EXTRA RELEVANT SYSTEM CONFIGURATION :
CGroups Configured

A DESCRIPTION OF THE PROBLEM :
version of JRE 1.8.0_141.b15 still has has the bug below 
https://bugs.openjdk.java.net/browse/JDK-6515172 

Even though per the ticket, it should have been resolved in JRE 1.8.0_141.b01 but still there 

Here is the code that was used to test the issue
public class Processors{ 
 public static void main(String []args) { 
   System.out.println("Available Processors: "+Runtime.getRuntime().availableProcessors()); 
 } 
} 

We have 4 core processor

Here are the execution results of above code on hrdvijh0401d 
$ ./jre1.8.0_141_bpr32-x86_64/bin/java -cp . Processors 
Available Processors: 1 
$ ./jre1.8.0_141-x86_64/bin/java -cp . Processors 
Available Processors: 1 
$ ./jre1.8.0_101-x86_64/bin/java -cp . Processors 
Available Processors: 4 



REGRESSION.  Last worked in version 8u131

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Here is the code that was used to test the issue
public class Processors{ 
 public static void main(String []args) { 
   System.out.println("Available Processors: "+Runtime.getRuntime().availableProcessors()); 
 } 
} 

We have 4 core processor

Here are the execution results of above code on hrdvijh0401d 
$ ./jre1.8.0_141_bpr32-x86_64/bin/java -cp . Processors 
Available Processors: 1 
$ ./jre1.8.0_141-x86_64/bin/java -cp . Processors 
Available Processors: 1 
$ ./jre1.8.0_101-x86_64/bin/java -cp . Processors 
Available Processors: 4 


REPRODUCIBILITY :
This bug can be reproduced always.


Comments
The information from the submitter is very confusing. The submitter needs to clearly explain their execution environment and show exactly what the output of the test program is for each of the different JDKs being tested. A VM with the 6515172 fix will return whatever sched_getaffinity provides for this process. If that answer is unexpected then that is a Linux issue. I suggest writing a simple C program to report what the cpu count from sched_getaffinity is.
19-10-2017

Additional information from submitter == We are not using taskset . We are using NUMA architecture and have the cpuset configured with controlled groups. However I am not running this application within those controlled groups (using cgexec) and even with controlled groups it should return more CPUs then what it is returning. ==
19-10-2017

8u131-b11 works fine for me: > /java/re/jdk/8u131/promoted/all/b11/binaries/linux-x64/bin/java Processors 24 > taskset -c 1 /java/re/jdk/8u131/promoted/all/b11/binaries/linux-x64/bin/java Processors 1 But the original report makes no mention of using taskset. In fact it seems to be simply showing that 8u101 does not have the 6515172 fix - which is correct. The reporting of only 1 processor is likely due to "CGroups Configured " - with cgroups only making 1 processor available.
04-10-2017

From submitter: We are using b11 of 8u131 Here is complete version info. java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
04-10-2017

The fix is definitely in "8u131" but it isn't clear to me what variant of 8u131 was tested?
04-10-2017

Given the configuration of submitter's system, and the test results on his system, it does seem a regression.
04-10-2017

From submitter: Here is the things you asked for lscpu: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 4 On-line CPU(s) list: 0-3 Thread(s) per core: 1 Core(s) per socket: 4 Socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 44 Model name: Intel(R) Xeon(R) CPU E5630 @ 2.53GHz Stepping: 2 CPU MHz: 2533.201 BogoMIPS: 5066.40 Virtualization: VT-x L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 12288K NUMA node0 CPU(s): 0-3 It worked with 8u101 and all previous versions. I did not try with 8u121 but did try with 8u131 2 weeks ago with latest build and also 8u141 -b15 . Both had the problem.
04-10-2017

To submitter: 1. Can you please provide us the output of ���lscpu��� on the system where you see the difference in the number of processors with JDK 8u101 and JDK 8u141. 2. Also, you have mentioned that this last worked on JDK 8u121, but the bug JDK-6515172 had been fixed in JDK 8u121 as well. So, we want a confirmation if this is an issue in JDK 8u121 as well or it worked well in that version.
03-10-2017