Should I use javac -O option to optimize?

后端 未结 3 1093
一向
一向 2021-01-01 11:47

javac has an interesting -O option:

Optimizes compiled code by inlining static, final and private methods. Note that your

相关标签:
3条回答
  • 2021-01-01 11:54

    I have been working with Java almost since its inception. I have built many systems, some of them high-performance, some of them extreme performance, and I have never, ever, found this flag useful. I think that it may have once had a use, but I have never needed to care.

    0 讨论(0)
  • 2021-01-01 11:58

    It is a no-op according to a comment in the source code around line 553.

    It was probably useful when the JIT compiler was not efficient yet or when there was no JIT compiler at all.

    0 讨论(0)
  • 2021-01-01 12:08

    I don't think It does any optimization as you think:

    -O Optimizes compiled code by inlining static, final and private methods. Note that your classes may get larger inj size.

    Please have a look into these questions:

    • Optimization by Java Compiler
    • Java code compiler optimization

    Update

    You won't find this in any Oracle documentation because it effectively does nothing at all (no-op). Moreover your link is a very very old documentation:

    Go up two directories in your link - It's the documentation for jdk 1.1.3. It's 13 - 14 years old! We are now on Jdk 7 and eagerly waiting for Jdk 8.

    0 讨论(0)
提交回复
热议问题