Why does JIT not compile huge methods
I was wondering why the JVM’s JIT compiler ignores “huge methods” from compilation. (Unless the DontCompileHugeMethods flag is set to false)
So here is the answer :
Basically the ROI of compiling huge methods is low.
1. Hot pieces of code are usually short.
2. Even if a huge method is executed frequently, the hot part is unlikely to cover the whole method. E.g. consider a large switch statement where
only a few case labels are executed often. However the compilation unit is a method – so the bigger part of JITted code would be a waste.
3. Compilation of huge methods takes much time and space. Moreover, the compilation time does not grow linearly. It would be more profitable to
compile several small methods instead.
4. Too long sheet of machine code pollutes instruction cache.
5. If a single method is larger than 8K bytecodes, it seems to be poorly written anyway.