On Thu, 25 Apr 2024 16:37:39 GMT, Alexey Ivanov <aiva...@openjdk.org> wrote:

> This PR provides a regression test for 
> [JDK-8325179](https://bugs.openjdk.org/browse/JDK-8325179): _Race in 
> BasicDirectoryModel.validateFileCache_ reviewed in #18111.
> 
> The test is inspired and based on `ConcurrentModification` that I wrote for 
> [JDK-8327137](https://bugs.openjdk.org/browse/JDK-8327137) / 
> [JDK-8323670](https://bugs.openjdk.org/browse/JDK-8323670).
> 
> **How the test works**
> 
> The test creates a temporary directory in the current directory and creates a 
> number of files in it. (The number of files is controlled by 
> `NUMBER_OF_THREADS` constant). Then the test creates `JFileChooser` in the 
> temporary directory.
> 
> The test starts several scanner threads, the number is controlled by 
> `NUMBER_OF_THREADS`, which repeatedly call 
> `fileChooser.rescanCurrentDirectory()`. This results in calling 
> `BasicDirectoryModel.validateFileCache` which starts a background thread — 
> "Basic L&F File Loading Thread" — to enumerate the files.
> 
> The test runner thread and scanner threads are synchronised with 
> `CyclicBarrier`, this ensures all the scanner threads start at the same time. 
> After a short delay, the runner thread takes a snapshot of live threads. 
> After a longer delay, the operation is repeated. See the `getThreadSnapshot` 
> method. (The number of snapshots is controlled by `SNAPSHOTS` constant.)
> 
> The number of File Loading Threads in each snapshot is counted. There should 
> be no more than two threads. It is possible that thread two such threads 
> after JDK-8325179 is fixed: the existing thread is interrupted but hasn't 
> exited yet, and a new thread is already created.
> 
> The test fails consistently without the fix for JDK-8325179. On Windows, the 
> output looks like this:
> 
> 
> Number of snapshots: 20
> Number of snapshots where number of loader threads:
>   = 1: 0
>   = 2: 0
>   > 2: 20
> java.lang.RuntimeException: Detected 20 snapshots with several loading threads
>         at LoaderThreadCount.runTest(LoaderThreadCount.java:132)
>         at LoaderThreadCount.wrapper(LoaderThreadCount.java:72)
>         at java.base/java.lang.Thread.run(Thread.java:1583)
> 
> 
> On Linux and macOS, there's more variation, for example I got the following 
> output on one of Linux systems:
> 
> 
> Number of snapshots: 15
> Number of snapshots where number of loader threads:
>   = 1: 7
>   = 2: 2
>   > 2: 6
> 
> 
> The test passes on the builds where JDK-8325179 is present.

Could you, @mrserb and @TejeshR13, take a look? You reviewed the test for 
[JDK-8323670](https://bugs.openjdk.org/browse/JDK-8323670) in #18109.

Those who reviewed [JDK-8325179](https://bugs.openjdk.org/browse/JDK-8325179) 
in #18111 — @prrace and @turbanoff — could be interested too.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/18957#issuecomment-2077726248

Reply via email to