JDK-8328769 : ForkJoinPool trims worker threads too quickly after JDK-8319662
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.concurrent
  • Affected Version: 22,23
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2024-03-22
  • Updated: 2024-09-06
  • Resolved: 2024-09-06
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.
Other
tbdResolved
Related Reports
Duplicate :  
Relates :  
Description
The changes in JDK-8319662 seem to have had an unintended side-effect. If you create a short-lived virtual thread, followed by a second, when the pool worker thread waits for its next task, it doesn't wait for anywhere near the keep-alive time, but instead keepAlive/parallelism based on this code:

             if (quiet) { // use timeout if trimmable
                    int nt = (short)(qc >>> TC_SHIFT);
                    long delay = keepAlive; // scale if not at target
                    if (nt != (nt = Math.max(nt, parallelism)) && nt > 0)
                        delay = Math.max(TIMEOUT_SLOP, delay / nt);
                    if ((deadline = delay + System.currentTimeMillis()) == 0L)
                        deadline = 1L; // avoid zero
                }

On my system with a parallelism of 16, the work thread times out and terminates after 1875ms instead of the expected keep-alive of 30 seconds (30000/16 = 1875).

This was detected via test/hotspot/jtreg/serviceability/jvmti/GetOwnedMonitorInfo/GetOwnedMonitorInfoTest.java - see JDK-8327743. I instrumented the test and FJP:

TEST: Virtual-Worker-Thread-0 is terminating at 1710894777172
TEST: Virtual-Worker-Thread-1 is terminating at 1710894778215
DEBUG: ForkJoinPool-1-worker-1 is terminating at 1710894780090 <= 1875ms after vthread terminated 
Comments
Re-closing as Duplicate of JDK-8322732
06-09-2024

Now works as expected.
06-06-2024

Oh, I forgot to add this to fixed in https://bugs.openjdk.org/browse/JDK-8322732 . Will do.
06-06-2024