Jitted array-length checks before entering a loop

Nassim Halli nassim.halli at gmail.com
Mon Sep 28 13:37:54 UTC 2015

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)

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

  test %r9d,%r9d
  jbe BB0

  mov %r9d,%r11d
  dec %r11d
  cmp %r9d,%r11d
  jae 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/20150928/faf542d2/attachment.html>

More information about the hotspot-compiler-dev mailing list