-XX:+StressCodeBuffers

Aleksey Shipilev shade at redhat.com
Tue May 17 09:12:31 UTC 2022


On 5/17/22 10:54, Andrew Haley wrote:
> Working on 8272094: compiler/codecache/TestStressCodeBuffers.java
> crashes..., I found that it took so long to reproduce the problem,
> even with many parallel runs, that I gave up. Even after hours it
> didn't show up.
> 
> Output from StressCodeBuffers looks like this:
> 
> StressCodeBuffers: have expanded 128 times
> StressCodeBuffers: have expanded 256 times
> StressCodeBuffers: have expanded 512 times
> StressCodeBuffers: have expanded 1024 times
> StressCodeBuffers: have expanded 2048 times
> 
> Each time this message is printed, a code buffer allocation fails. So
> it only tests code buffer allocation failure a few times.
> 
> I changed the logic (patch below) to make codeBuffer allocation fail
> much more frequently, every 40 times, and "Boom!" I reproduced the
> bug immediately. Every run, in fact.
> 
> So, my question is: why is -XX:+StressCodeBuffers so very gentle? It
> seems to me like it's not even trying to stress the system.

Good question. In fact, it is strange to see exponential backoff in stress option.

I suspect it was that way because it was enough to manifest some other bug at the time. Given the 
evidence that a more frequent allocation failure is beneficial for testing, there should be no 
problem in bumping the frequency. (

> diff --git a/src/hotspot/share/asm/codeBuffer.cpp b/src/hotspot/share/asm/codeBuffer.cpp
> index ddd946d7542..c74ba21cf63 100644
> --- a/src/hotspot/share/asm/codeBuffer.cpp
> +++ b/src/hotspot/share/asm/codeBuffer.cpp
> @@ -837,7 +837,8 @@ void CodeBuffer::expand(CodeSection* which_cs, csize_t amount) {
>      if (StressCodeBuffers && blob() != NULL) {
>        static int expand_count = 0;
>        if (expand_count >= 0)  expand_count += 1;
> -    if (expand_count > 100 && is_power_of_2(expand_count)) {
> +    if (expand_count > 100 && // is_power_of_2(expand_count)
> +        expand_count % 40 == 0) {
>          tty->print_cr("StressCodeBuffers: have expanded %d times", expand_count);
>          // simulate an occasional allocation failure:
>          free_blob();

In fact, that whole code could be simplified to just e.g.:

   if (StressCodeBuffers && blob() != NULL) {
     static int expand_count = 0;
     if ((++expand_count % 100) == 0) {
       tty->print_cr("StressCodeBuffers: have expanded %d times", expand_count);
       // simulate an occasional allocation failure:
       free_blob();
     }
   }


-- 
Thanks,
-Aleksey



More information about the hotspot-compiler-dev mailing list