javac 优化标志 [英] javac optimization flags

查看:32
本文介绍了javac 优化标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近用 C 编写了很多代码,现在正在切换到 Java.我目前正在实现一个大型数据结构,想知道在调用 Java 编译器时是否可以打开任何优化标志,以便像在 gcc 中一样提高性能.

I've recently been writing a lot of code in C and am now switching over to Java. I'm currently implementing a large data structure and was wondering whether there were any optimization flags I can turn on when I invoke the Java compiler in order to improve performance like in gcc.

我习惯了:

gcc -O3 -NDEBUG MyProgram.c

javac 是否有类似的命令?

我正在使用 JDK 并运行 Ubuntu 10.04.

I'm using JDK and am running Ubuntu 10.04.

推荐答案

Java 中的优化主要由 JIT 编译器在运行时完成.因此,在编译时尝试指示它以某种方式优化是没有意义的(当它只创建字节码时).JIT 几乎肯定会在现场做出更好的决策,了解确切的环境并观察代码特定部分的实际执行模式.

Optimization in Java is mostly done by the JIT compiler at runtime. Hence there is no point trying to instruct it to optimize a certain way at compile time (when it is creating only bytecode anyway). The JIT will almost surely make better decisions on the spot, knowing the exact environment and observing the actual patterns of execution of specific parts of your code.

有一些特定的编译器选项会影响性能,但这些选项用于调整 JVM(包括垃圾收集器)而不是优化代码本身.

There are some specific compiler options affecting performance, but these are for tuning the JVM (including the garbage collector) rather than optimizing the code itself.

这篇关于javac 优化标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆