导航:首页 > 源码编译 > 编译命令不包含优化吗

编译命令不包含优化吗

发布时间:2025-04-15 23:33:19

1. 编译型语言和解释型语言详解

编译型语言与解释型语言详解

编译型语言需通过编译器将源代码转换为机器码,之后才能执行,一般包含编译与链接两步骤。优点在于,编译过程通常包含优化,执行效率高且程序可独立运行。但修改代码需重新编译,并且不同操作系统间移植存在挑战,需为每个运行环境编译不同可执行文件。代表语言包括C、C++、Pascal、Object-C及Swift。

解释型语言在运行时逐行翻译程序,相比编译型语言省去了编译步骤,具备良好平台兼容性与灵活性,修改代码无需重新编译。然而,性能上不如编译型语言,因为每次运行都需解释。代表语言有javaScript、Python、Erlang、PHP、Perl、Ruby。

混合型语言整合编译型与解释型语言的长处,取其精华,去其糟粕。例如C#在编译阶段生成中间码,通过.NET平台的中间语言运行库运行,提高了性能。Java先生成字节码,在Java虚拟机中解释执行。严格来说,混合型语言属于解释型语言,但接近编译型语言。

动态语言与静态语言区分在于运行时是否能改变结构。动态语言如Object-C、C#、JavaScript、PHP、Python、Erlang允许在运行时改变代码结构,而静态语言如Java、C、C++在编译阶段确定结构。动态类型语言如Python、Ruby、Erlang、JavaScript、swift、PHP、Perl在运行时进行数据类型检查,而静态类型语言如C、C++、C#、Java、Object-C在编译阶段确定数据类型。

强类型语言一旦定义了数据类型,除非强制转换,否则不能改变。代表语言有Java、C#、Python、Object-C、Ruby。弱类型语言允许在运行时改变数据类型,如JavaScript、PHP、C、C++,允许字符与整数之间的转换。

理解编译型语言与解释型语言的区别有助于选择适合项目需求的语言。每种类型都有其优势与局限性,结合项目实际需求与团队技能,选择最合适的语言是关键。如需更深入讨论或有疑问,请在Python学习群473391225交流。

2. 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.

阅读全文

与编译命令不包含优化吗相关的资料

热点内容
源码无忧app 浏览:969
k线图pdf下载 浏览:776
加密货币推广工作 浏览:117
什么app聊天无痕迹 浏览:844
dism压缩 浏览:620
在线版迅捷pdf转换器 浏览:245
pdf怎么建 浏览:913
4的次方怎么算法 浏览:784
方舟端游如何开私人服务器 浏览:120
远程服务器云帮手 浏览:391
单片机接排阻 浏览:344
迅雷云服务器搭建 浏览:656
php变量转字符串 浏览:172
只读文件保存到原来文件夹就没了 浏览:49
php远程执行linux命令 浏览:644
加密货币nft价值 浏览:854
程序员用的网站有哪些 浏览:397
php简单代码下载 浏览:857
android读取内存卡 浏览:150
linux如何删除php 浏览:189