On Wed, 16 Aug 2023 10:33:58 GMT, Doug Lea <d...@openjdk.org> wrote: >> src/java.base/share/classes/java/util/concurrent/ForkJoinPool.java line 442: >> >>> 440: * queues are at odd indices. Worker phase ids masked with SMASK >>> 441: * match their index. Shared (submission) queues are at even >>> 442: * indices. Grouping them together in this way simplifies and >> >> @DougLea Interesting—so by having the worker queues at odd indices increases >> the likelihood of the then adjacent submission queues already having been >> prefetched? > > More-or-less. At top-level, both kinds of queues should be sampled with > approx the same probability, which is simpler if they are all in the same > array. But we also need to identify what kind they are without looking at > them, leading to odd/even scheme. One disadvantage is that there are usually > many fewer submission queues, so there can be a lot of wasted probes (null > slots). But still cheaper than alternatives because of cache locality etc.
(I also added some similar wording to the internal docs.) ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/14301#discussion_r1297226372