JDK-8264572 : ForkJoinPool.getCommonPoolParallelism() reports always 1
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 17
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2021-03-31
  • Updated: 2021-04-13
  • Resolved: 2021-04-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 17
17 b17Fixed
Related Reports
Duplicate :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Win10 20H2 (Build19042.868)
Java: 17-ea+11-835
CPU: i7-8700K

A DESCRIPTION OF THE PROBLEM :
A call to ForkJoinPool.getCommonPoolParallelism() will report "1" on my machine (JDK 16 = 11!)

If you think its a "special" problem on my machine - contact me.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Just run getCommonPoolParallelism() 

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Version: java.version: 16, OpenJDK 64-Bit Server VM, 16+36-2231
OS:      Windows 10 Version 10.0 (amd64) 
CPUs:    12
fjp:     11
ACTUAL -
Version: java.version: 17-ea, OpenJDK 64-Bit Server VM, 17-ea+11-835
OS:      Windows 10 Version 10.0 (amd64) 
CPUs:    12
fjp:     1

---------- BEGIN SOURCE ----------
public class TestFjp {

	public static void main(String[] args) {	
		System.out.println("Version: " + getJavaVersion());
		System.out.println("OS:      " + getOsInofrmation());
		System.out.println("CPUs:    " + Runtime.getRuntime().availableProcessors());
		System.out.println("fjp:     " + ForkJoinPool.getCommonPoolParallelism());
	}

	private static String getJavaVersion() {
		return "java.version: " //
				+ System.getProperty("java.version")//
				+ ", " + System.getProperty("java.vm.name")//
				+ ", " + System.getProperty("java.runtime.version");
	}
	
	private static String getOsInofrmation() {
		return System.getProperty("os.name") + " Version "
				+ System.getProperty("os.version") + " (" + System.getProperty("os.arch") + ") ";
	}	
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Using "Runtime.getRuntime().availableProcessors())" won't work on foreign software.

FREQUENCY : always



Comments
From the submitter: i could confirm that the problem is solved with jdk 17ea+17-1401.
13-04-2021

Request the submitter to verify the fix with the latest version of JDK at https://jdk.java.net/17/
12-04-2021

Changeset: cec66cf8 Author: Doug Lea <dl@openjdk.org> Date: 2021-04-02 22:44:20 +0000 URL: https://git.openjdk.java.net/jdk/commit/cec66cf8
02-04-2021

After some fumbling, the one-line fix is at https://github.com/openjdk/jdk/pull/3324
02-04-2021

Sorry the assignment got dropped in JDK-8259800! I'll generate pull request tomorrow.
01-04-2021

AFAICS JDK-8259800 skipped setting of this.mode in the common pool constructor, but that value is still used to set COMMON_PARALLELISM. - int p = this.mode = Math.min(Math.max(parallelism, 0), MAX_CAP); + int p = Math.min(Math.max(parallelism, 0), MAX_CAP), size; common = AccessController.doPrivileged(new PrivilegedAction<>() { public ForkJoinPool run() { return new ForkJoinPool((byte)0); }}); COMMON_PARALLELISM = Math.max(common.mode & SMASK, 1); Stylistically declaring size on the same line as p is awful - sorry Doug.
01-04-2021

I have to suspect that JDK-8259800 has introduced this bug as it went into build b11 as reported.
01-04-2021

The observations on Windows 10: JDK 17ea+12: Passed, fjp: 7
01-04-2021