Jitted array-length checks before entering a loop

Christian Thalinger christian.thalinger at oracle.com
Fri Oct 9 18:31:11 UTC 2015


> On Sep 28, 2015, at 3:37 AM, Nassim Halli <nassim.halli at gmail.com> wrote:
> 
> Hi guys,
> 
> I have a question relative to some code generated by the C2 compiler.
> 
> When I look at the assembly codes for this method:
> 
>     static void compiledMethod (Atype[] data) {
>         int n = data.length
>         for (int i = 0; i < n; ++i) 
>             data[i].amethod();
>     }
> 
> I get the this assembly on Linux X86_64 before entering the loop (not OSR):
> 
> # data is in rbx
>   mov 0xc(%rbx),%r9d
> 
> # data.length is in r9d                     
>   test %r9d,%r9d                                                      
>   jle END_OF_LOOP   
>                                              
>   test %r9d,%r9d                                
>   jbe BB0
>                  
>   mov %r9d,%r11d                             
>   dec %r11d                                 
>   cmp %r9d,%r11d                              
>   jae BB0                      
> 

Did you leave out any assembly?  Where is BB0?

> 
> It seems to me the second and third check are useless and the corresponding branches are never taken. 
> Could you please tell me more about these checks, If and why are they required ? 
> 
> Thanks a lot.
> 
> Nassim H.
> 
> 
> Test conditions:
> 
> java version "1.8.0_51"
> Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
> Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
> Default options.
> Linux, Intel Sandy Bridge core i5-2000

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20151009/b6924806/attachment-0001.html>


More information about the hotspot-compiler-dev mailing list