Skip to content

Scan the paths of a search outside the lock of the output map - #46

Merged
Roberto-Gentili merged 1 commit into
masterfrom
claude/class-path-scanner-output-lock
Nov 29, 2026
Merged

Roberto-Gentili merged 1 commit into
masterfrom
claude/class-path-scanner-output-lock

Conversation

@Roberto-Gentili

@Roberto-Gentili Roberto-Gentili commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

In the scheduled run of 20 November, the JDK 23 job (136598864135) stood still for about 8.5 minutes in RepeatedComponentContainerTest.deepClearTestTwo. The thread dumps logged by the Synchronizer at 22:50 and 22:53 are the same: nine threads are blocked on synchronized (output) in IterableObjectHelperImpl.Iterator.buildOutputCollectionHandler, while the two threads that hold those monitors wait in TaskBasedIterator.iterate for the subtasks of FileSystemItem.findInAllChildren. Only one thread was working, on the entries of jmods/jdk.compiler.jmod/lib/ct.sym. It was not a deadlock: when that thread finished, the three searches of the after-init operations completed within a second, and the tasks monitor never reported a possible deadlock.

The cause is in ClassPathScanner.Abst.findBy. It scanned every path inside the output handler, outputHandler.accept(output -> output.put(path, scanAndAddToPathScannerClassLoader(context, path))), and the iterator runs the handler in a block synchronized on the output map, because ConcurrentHashMap is not one of the output types considered concurrent: the default list holds only collections, such as ConcurrentHashMap$CollectionView. The paths of a search were therefore scanned one at a time, and a slow path kept all the other workers of the search blocked. The scan moved into the handler in 90f98ef (Adaptation to the new IterableObjectHelper interface, November 2021); before, it ran outside any lock.

  • findBy now scans the path before calling the output handler, and only the put runs in the synchronized block.
  • The new test ClassHunterTest.findAllInParallelTestOne searches two paths with a file filter that waits, for at most 30 seconds, until both paths are being scanned. On master it fails with expected: <[true, true]> but was: <[false, true]>, because the second path cannot start while the first holds the monitor. It is skipped on a machine with a single processor.
  • The default list of the concurrent output types is unchanged: adding ConcurrentMap to it would also remove the synchronization from user code that runs compound operations on the map inside the handler.

How this is tested. The workflow Build and test (pull requests), added to master in 46120d2, ran on this pull request merged with master at that commit: all 59 jobs (JDK 8 to 27 on Windows, macOS and Ubuntu, the same matrix as [A] build and test, release if requested) passed. On the first attempt the JDK 10 job on macOS stopped at the 30-minute timeout, with no log available; the rerun passed in under 8 minutes. Locally, on Windows with JDK 21 and 16 processors:

  • the new test fails 2 times out of 2 on master and passes 3 times out of 3 with the change;
  • three concurrent find() of ClassHunter, ClassPathHunter and ByteCodeHunter on the default paths, the jmods of the JDK included, took 34.1, 37.4 and 34.3 seconds on master, with threads blocked on the monitor of the output map in 71-81% of the samples taken every 50 ms (up to 45 threads), and 27.4, 32.3 and 29.7 seconds with the change, with no thread blocked on that monitor;
  • AllExceptHeavyTestsSuite: 285 tests, no failures, 2 skipped.

Limits. The change does not make a slow path faster: in the JDK 23 job most of the 8.5 minutes went into the entries of the nested ct.sym, so test jobs of 11-13 minutes may still happen. With more paths scanned at the same time, the memory used during a search may be higher.

🤖 Generated with Claude Code

ClassPathScanner.findBy scanned every path inside the output handler, and
the iterator runs that handler in a block synchronized on the output map,
because ConcurrentHashMap is not one of the output types considered
concurrent. The paths of a search were therefore scanned one at a time, and
a slow path kept all the other workers of the search blocked on the monitor
of the map. The scan moved into the handler in 90f98ef (Adaptation to the
new IterableObjectHelper interface); before, it ran outside any lock.

Now the path is scanned before the handler is called, and only the put runs
in the synchronized block. The new test findAllInParallelTestOne of
ClassHunterTest checks that two paths of a search are scanned at the same
time.
@Roberto-Gentili
Roberto-Gentili merged commit 09eeb3b into master Nov 29, 2026
117 of 118 checks passed
@Roberto-Gentili
Roberto-Gentili deleted the claude/class-path-scanner-output-lock branch November 29, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant