This is contrived/minimalistic example (inlining is just to make the asm easier to read), but shows the point. This originally came up in a case where arr was generated in an event processing critical path, and this iteration over a (usually empty array) was creating millions of objects that escaped to heap (due to storage in another object, not assignment to a global), eating ~10% of run time.
What did you expect to see?
I would expect that the runtime.newobject call would only happen after the array is checked for length > 0.
This is more or less intentional. We want that allocation to happen outside the loop, so it only happens once even if the loop has many iterations. Of course, that's pessimistic if the loop has 0 iterations.
We could condition the allocation by checking the number if iterations first. Offhand I suspect this would be fairly hard to do, just because it requires some form of loop peeling. But it would be nice to handle this case.