On Mon, 29 Apr 2024 19:59:18 GMT, Alexey Ivanov <[email protected]> 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.
>
> Alexey Ivanov has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Suppress throwing exceptions while deleting files

Looks Good to me.

Marked as reviewed by tr (Committer).

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

Marked as reviewed by tr (Committer).

PR Review: https://git.openjdk.org/jdk/pull/18957#pullrequestreview-2031028809
PR Review: https://git.openjdk.org/jdk/pull/18957#pullrequestreview-2031029437

Reply via email to