Why javac does not optimize even simple code?

后端 未结 2 872
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-18 00:41

Given the following code:

public class MainClass {
    public static int f(){
        int i=0;
        i++;
        return i;
    }
}

the c

2条回答
  •  难免孤独
    2021-01-18 01:33

    Is so directly translated that it makes me hard to believe that java compiler does any optimizations at all.

    Indeed. Most Java optimization is performed at JIT-time instead. The Java maintainers found out quite a while ago that in many cases, optimizations performed at compile-time actually hindered more important optimizations at JIT-time.

    For a few years now, the -O command-line argument has done nothing - and very deliberately so.

提交回复
热议问题