I would like to know what are the loop optimizations performed by Oracle Java 7 (or 8) Hotspot VM?
Asked
Active
Viewed 2,019 times
9
-
3The compiler writers possibly could ... but I doubt that they would. Anyway, if you really need to know you can always download the OpenJDK source tree and figure it out for yourself. – Stephen C Oct 01 '15 at 14:33
-
The main ones will probably be deadcode elimination, loop unrolling and variable hoisting. – assylias Oct 01 '15 at 14:45
-
4@ The close voters: In how far is this asking for an off-site resource? Look at the current answer. (Of course, it has lots of links in it, but these are only pointers to a durable resource (namely, the OpenJDK source), and intended for further research). – Marco13 Oct 03 '15 at 13:41
-
2@ The close voters: I have edited my question 2 days a go. Can you check this please? Thanks – El Marce Oct 06 '15 at 10:31
1 Answers
28
- Range Check Elimination - eliminates range checks for loop-invariant arrays. See PhaseIdealLoop::do_range_check for details. The optimization is controlled by the flag
-XX:+RangeCheckElimination
- Loop Peeling - splits first iteration from the loop and performs it outside of the loop body. See amazing description here PhaseIdealLoop::do_peeling. This optimization is controlled by the flag
-XX:PartialPeelLoop=true
- Loop Predication - eliminates the condition checks from inside the loop body. Currently, loop predication optimization has been applied to remove array range check and loop invariant checks (such as null checks and array checks). Loop predication is controlled by the
-XX:+UseLoopPredicate
. See code PhaseIdealLoop::loop_predication_impl - Loop Unrolling - is used as first step of Superword Level Parallelism. See PhaseIdealLoop::do_unroll. Loop unrolling is controlled by the following properties:
-XX:LoopMaxUnroll=16
and-XX:LoopUnrollMin=4
- Array Filling - replaces any fill patterns with an intrisc. See PhaseIdealLoop::do_intrinsify_fill. JVM option
-XX:+OptimizeFill
- Vectorization - replaces array initialization, copy and arithmetic with vector operations in unrolled loops. The Hotspot compiler implements the concept of Superword Level Parallelism in superword.cpp. See also JVM option
-XX:+UseSuperWord

El Marce
- 3,144
- 1
- 26
- 40

Ivan Mamontov
- 2,874
- 1
- 19
- 30
-
-
3Very helpful! Her's some complementary info: [VectorizaAon in HotSpot JVM by Vladimir Ivanov, HotSpot JVM Compiler, Oracle Corp. April 8, 2017](http://cr.openjdk.java.net/~vlivanov/talks/2017_Vectorization_in_HotSpot_JVM.pdf) – apete Oct 28 '17 at 07:56
-
1More recent version of that great presentation: http://cr.openjdk.java.net/~vlivanov/talks/2019_CodeOne_MTE_Vectors.pdf – Antoine CHAMBILLE Jan 06 '21 at 16:26