导航:首页 > 源码编译 > 即时编译的优化

即时编译的优化

发布时间:2022-01-13 21:55:05

java 编译优化问题

java编译的结果是字节码而不是二进制,所以在运行时vm的优化才是重要的,包括VM的回收策略、分配给VM内存的大小都能在一定程度上影响性能。Sun的VM支持热点编译,对高频执行的代码段翻译的2进制会进行缓存,这也是VM的一种优化。

IBM JVM处理数学运算速度最快,BEA JVM处理大量线程和网络socket性能最好,而Sun JVM处理通常的商业逻辑性能最好。不过Hotspot的Server mode被报告有稳定性的问题。

Java 的最大优势不是体现在执行速度上,所以对Compiler的要求并不如c++那样高,代码级的优化还需要程序员本身的功底。

贴个java的运行参数:

Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)

where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.

-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print proct version and exit
-version:<value>
require the specified version to run
-showversion print proct version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see

java.lang.instrument

-Xmixed mixed mode execution (default)
-Xint interpreted mode execution only
-Xbootclasspath:<directories and zip/jar files separated by ;>
set search path for bootstrap classes and resources
-Xbootclasspath/a:<directories and zip/jar files separated by ;>
append to end of bootstrap class path
-Xbootclasspath/p:<directories and zip/jar files separated by ;>
prepend in front of bootstrap class path
-Xnoclassgc disable class garbage collection
-Xincgc enable incremental garbage collection
-Xloggc:<file> log GC status to a file with time stamps
-Xbatch disable background compilation
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
-Xss<size> set java thread stack size
-Xprof output cpu profiling data
-Xfuture enable strictest checks, anticipating future default
-Xrs rece use of OS signals by Java/VM (see

documentation)
-Xcheck:jni perform additional checks for JNI functions
-Xshare:off do not attempt to use shared class data
-Xshare:auto use shared class data if possible (default)
-Xshare:on require using shared class data, otherwise fail.

Java虚拟机(JVM)参数配置说明

在Java、J2EE大型应用中,JVM非标准参数的配置直接关系到整个系统的性能。
JVM非标准参数指的是JVM底层的一些配置参数,这些参数在一般开发中默认即可,不需

要任何配置。但是在生产环境中,为了提高性能,往往需要调整这些参数,以求系统达

到最佳新能。
另外这些参数的配置也是影响系统稳定性的一个重要因素,相信大多数Java开发人员都

见过“OutOfMemory”类型的错误。呵呵,这其中很可能就是JVM参数配置不当或者就没

有配置没意识到配置引起的。

为了说明这些参数,还需要说说JDK中的命令行工具一些知识做铺垫。

首先看如何获取这些命令配置信息说明:
假设你是windows平台,你安装了J2SDK,那么现在你从cmd控制台窗口进入J2SDK安装目

录下的bin目录,然后运行java命令,出现如下结果,这些就是包括java.exe工具的和

JVM的所有命令都在里面。

-----------------------------------------------------------------------
D:\j2sdk15\bin>java
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)

where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.

-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print proct version and exit
-version:<value>
require the specified version to run
-showversion print proct version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see

java.lang.instrument
-----------------------------------------------------------------------
在控制台输出信息中,有个-X(注意是大写)的命令,这个正是查看JVM配置参数的命

令。

其次,用java -X 命令查看JVM的配置说明:
运行后如下结果,这些就是配置JVM参数的秘密武器,这些信息都是英文的,为了方便

阅读,我根据自己的理解翻译成中文了(不准确的地方还请各位博友斧正)
-----------------------------------------------------------------------
D:\j2sdk15\bin>java -X
-Xmixed mixed mode execution (default)
-Xint interpreted mode execution only
-Xbootclasspath:<directories and zip/jar files separated by ;>
set search path for bootstrap classes and resources
-Xbootclasspath/a:<directories and zip/jar files separated by ;>
append to end of bootstrap class path
-Xbootclasspath/p:<directories and zip/jar files separated by ;>
prepend in front of bootstrap class path
-Xnoclassgc disable class garbage collection
-Xincgc enable incremental garbage collection
-Xloggc:<file> log GC status to a file with time stamps
-Xbatch disable background compilation
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
-Xss<size> set java thread stack size
-Xprof output cpu profiling data
-Xfuture enable strictest checks, anticipating future default
-Xrs rece use of OS signals by Java/VM (see

documentation)
-Xcheck:jni perform additional checks for JNI functions
-Xshare:off do not attempt to use shared class data
-Xshare:auto use shared class data if possible (default)
-Xshare:on require using shared class data, otherwise fail.

The -X options are non-standard and subject to change without notice.
-----------------------------------------------------------------------

JVM配置参数中文说明:
-----------------------------------------------------------------------
1、-Xmixed mixed mode execution (default)
混合模式执行

2、-Xint interpreted mode execution only
解释模式执行

3、-Xbootclasspath:<directories and zip/jar files separated by ;>
set search path for bootstrap classes and resources
设置zip/jar资源或者类(.class文件)存放目录路径

3、-Xbootclasspath/a:<directories and zip/jar files separated by ;>
append to end of bootstrap class path
追加zip/jar资源或者类(.class文件)存放目录路径

4、-Xbootclasspath/p:<directories and zip/jar files separated by ;>
prepend in front of bootstrap class path
预先加载zip/jar资源或者类(.class文件)存放目录路径

5、-Xnoclassgc disable class garbage collection
关闭类垃圾回收功能

6、-Xincgc enable incremental garbage collection
开启类的垃圾回收功能

7、-Xloggc:<file> log GC status to a file with time stamps
记录垃圾回日志到一个文件。

8、-Xbatch disable background compilation
关闭后台编译

9、-Xms<size> set initial Java heap size
设置JVM初始化堆内存大小

10、-Xmx<size> set maximum Java heap size
设置JVM最大的堆内存大小

11、-Xss<size> set java thread stack size
设置JVM栈内存大小

12、-Xprof output cpu profiling data
输入CPU概要表数据

13、-Xfuture enable strictest checks, anticipating future default
执行严格的代码检查,预测可能出现的情况

14、-Xrs rece use of OS signals by Java/VM (see

documentation)
通过JVM还原操作系统信号

15、-Xcheck:jni perform additional checks for JNI functions
对JNI函数执行检查

16、-Xshare:off do not attempt to use shared class data
尽可能不去使用共享类的数据

17、-Xshare:auto use shared class data if possible (default)
尽可能的使用共享类的数据

18、-Xshare:on require using shared class data, otherwise fail.
尽可能的使用共享类的数据,否则运行失败

The -X options are non-standard and subject to change without notice.

⑵ java如何优化编译呢

#java编译器对`String常量表达式`的优化:
- 1.String+String 可以被编译器识别为常量表达
String a="ab" ;
String b="a"+"b";//编译后:b="ab"
System.out.println(a==b);//true
分析:
编译器将"a"+"b"当做常量表达式,在编译时期进行优化,直接取"ab". 在运行时期
并没有创建新的对象,而是从jvm字符串常量池中获取之前已经存在的"ab"对象.

- 2.String+基本类型 可以被编译器识别为常量表达式

String a="a1";
String b="a"+1; //"a1"
String c="a"+true;//"atrue"
String d="a"+3.14;//"a3.14"

#java编译器对`常量`优化:
* 它是编译时的一项优化技术,将代码的常量计算在编译期完成,节约了运行时的计算量.

1.常量替换
//编译前:
final int x=10;
int y=x;

//编译后
int x=10;
int y=10;//编译时,常量替换了

2.数学恒等式的模式匹配替换

//编译前:
int x=10+10;

//编译后
int x=20;//编译时,模式匹配替换了

3.常量折叠

//编译前:
boolean flag=true||(a || b && c);

//编译后
boolean flag=true;//编译时,常量折叠了

⑶ 什么是预编译和实时编译

预编译就是在你代码编译之前做的一些动作,比如你代码里写了
#define size 10
int a[size];
预编译就会把这个size替换掉
int a[10];

实时编译,一般是指那些动态语言,在执行到该代码的时候进行编译,例如
scipy.weave 里面可以嵌入C代码,并在程序的执行过程中,调用gcc编译器把这段C代码编译成二进制,并调用其中的函数执行。

⑷ C++编译器即时编译问题。

断点中断后所在的行是尚未运行准备运行的行,你可以按F10单步运行过去之后,就看到结果了。

if(ia[x++]<ia[x])

这句中由于 ++ 在后,所以判断运算先进行,然后再增一,这种前后书写有关系只有在多重运算下才会生效,单独的 x++ 和 ++x 没有区别。

⑸ 用编辑器写代码有什么好的办法即时编译吗

现在很少有语言支持立即编译了

⑹ 编译原理优化遵循哪些原则

真好奇的话,可以去翻翻《编译原理》。不然,咱们只需要知道:1、优化有执行速度优化和空间优化两种;2、优化级别越高,对代码编写质量的要求越高。如恰当地应用递归,使用volatile关键字等等,所以现实工程中一般不会开到最高优化级;3、想不出来了。。

⑺ 请教JAVA一个即时编译的问题

全部翻译成机器指令,哪怕实际上这些部分并没有执行到

你认为这会更快?

⑻ 即时编译器和JAVA解释器的区别

即时编译器预先把程序编译完成,当执行时就直接调用。
而JAVA解释器则是当需要调用该代码时才临时编译解释,而且没执行一次就要编译一次,而即时编译器则是一次编译多次执行。

⑼ 编译器 优化

编译是从源代码(通常为高阶语言)到能直接被计算机或虚拟机执行的目标代码(通常为低阶语言或机器语言)的翻译过程。然而,也存在从低阶语言到高阶语言的编译器,这类编译器中用来从由高阶语言生成的低阶语言代码重新生成高阶语言代码的又被叫做反编译器。也有从一种高阶语言生成另一种高阶语言的编译器,或者生成一种需要进一步处理的的中间代码的编译器(又叫级联)。
典型的编译器输出是由包含入口点的名字和地址, 以及外部调用(到不在这个目标文件中的函数调用)的机器代码所组成的目标文件。一组目标文件,不必是同一编译器产生,但使用的编译器必需采用同样的输出格式,可以链接在一起并生成可以由用户直接执行的可执行程序。
从他的原理我们就好优化了,但是方法很多的

⑽ 什么是即时编译技术

JIT(just-in-time compilation)指计算机领域里,即时编译也被成为动态翻译,是一种通过在运行时将字节码翻译为机器码,从而改善字节码编译语言性能的技术。即时编译前期的两个运行时理论是字节码编译和动态编译。

在编译为字节码的系统如 Limb 编程语言,Smalltalk, UCSD P-System, Perl, GNU CLISP, 和 Java 的早期版本中, 源代码被翻译为一种中间表示即字节码。 字节码不是任何特定计算机的机器码, 它可以在多种计算机体系中移植。字节码被解释着运行在虚拟机里。

动态编译环境是一种在执行时使用编译器的编译环境。 例如, 多数 Common Lisp 系统有一个编译函数,他可以编译在运行时创建的函数。

在即时编译环境下, 字节码的编译是第一步, 它将源代码递归到可移植和可优化的中间表示。字节码被部署到目标系统。 当执行代码时,运行时环境的编译器将字节码翻译为本地机器码。 基于每个文件或每个函数:函数仅仅在他们要被执行时才会被编译。

目标是要组合利用本地和字节码编译的多种优势:多数重量级的任务如源代码解析和基本性能的优化在编译时处理,将字节码编译为机器码比起从源代码编译为机器码要快得多。部署字节码是可移植的,而机器码只限于特定的系统结构。从字节码到机器码编译器的实现更容易,因为大部分工作已经在实现字节码编译器时完成。

阅读全文

与即时编译的优化相关的资料

热点内容
单片机下载口叫什么 浏览:186
程序员的道 浏览:924
云服务器不实名违法吗 浏览:555
怎样查看文件夹图片是否重复 浏览:993
文件怎么导成pdf文件 浏览:805
打开sql表的命令 浏览:101
安卓手机如何面部支付 浏览:37
天元数学app为什么登录不上去 浏览:822
明日之后为什么有些服务器是四个字 浏览:102
安卓系统l1是什么意思 浏览:24
服务器一直崩应该用什么指令 浏览:922
cm202贴片机编程 浏览:727
php构造函数带参数 浏览:177
解压电波歌曲大全 浏览:344
为啥文件夹移到桌面成word了 浏览:858
命令符的安全模式是哪个键 浏览:758
编程中学 浏览:956
单片机求助 浏览:995
ug加工侧面排铣毛坯怎么编程 浏览:273
程序员有关的介绍 浏览:738