Repository navigation
Scan the paths of a search outside the lock of the output map - #46
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 onsynchronized (output)inIterableObjectHelperImpl.Iterator.buildOutputCollectionHandler, while the two threads that hold those monitors wait inTaskBasedIterator.iteratefor the subtasks ofFileSystemItem.findInAllChildren. Only one thread was working, on the entries ofjmods/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, becauseConcurrentHashMapis not one of the output types considered concurrent: the default list holds only collections, such asConcurrentHashMap$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.findBynow scans the path before calling the output handler, and only theputruns in the synchronized block.ClassHunterTest.findAllInParallelTestOnesearches two paths with a file filter that waits, for at most 30 seconds, until both paths are being scanned. Onmasterit fails withexpected: <[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.ConcurrentMapto 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
masterin 46120d2, ran on this pull request merged withmasterat 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:masterand passes 3 times out of 3 with the change;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 onmaster, 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