It's the same number of instructions either way, and as pointed out already the spec doesn't tie the compiler to this particular bytecode:
A compiler might compile spin to...
The compiler can pretty much choose to compile it to whatever bytecode it wants, as long as the end effect is the same.
Placing condition after body prevents us from doing goto after every cycle and looks logical to me. So why is OracleJDK doing another way?
Probably impossible to say for definite unless the guy that wrote that bit of the compiler swings by - however I'd imagine your theory could be correct in that it seems possible it's to do with aiding later JIT optimisation. My only hunch (which may be incorrect) is that it could be to do with the positioning of the goto
command - there may be some more potential for better code inlining if the first 6 instructions are taken as a logical block, with no gotos, as they are in the bytecode that the compiler actually produces. Of course, since that particular goto
can only ever jump to within that block there's no logical difference, and the JIT could still inline it with exactly the same effect. These days I'd imagine it's clever enough to work that out, but it may not have always been, in which case the produced code provides a good work around. Of course, when (if) the JIT was made clever enough, there was no need to change the code, so it stuck.
An elaborate theory, and perhaps completely wrong - but if it is a functional difference, that's my best guess!
The other possibility is that it's just how that part of the compiler has been written, is completely coincidental, and there's no set reason for it at all (as in the compiler devs probably weren't trying to make the code turn out exactly as it did in the example.)