當前位置:首頁 » 編程軟體 » 編譯系統優化領域

編譯系統優化領域

發布時間: 2023-06-09 10:15:15

1. 編譯原理除了可以用來編寫編譯器,還在哪些領域可以用到編譯原理的知識

很多的,例如MASM編譯器。
編譯原理內容包括語言和文法、詞法分析、語法分析、語法制導翻譯、中間代碼生成、存儲管理、代碼優化和目標代碼生成等,這門課大部分人聽起來比較困難,介紹編譯程序構造的一般原理和基本方法,雖然只有少數人從事編譯方面的工作,但是這門課在理論、技術、方法上都對我們提供了系統而有效的訓練,有利於提高軟體人員的素質和能力。

2. 應用編譯優化有什麼用

應用編譯優化的作用是:提高運行能力因為程序優化前,有3個變數需要3個寄存器,一次乘法運算。程序優化後,只有1個變數需要一個寄存器,沒有乘法運算。

並且這個優化看起來很微不足道,但實際上用途很廣。為了程序的可讀性和可維護性,大多數程序員應該還是會選用第一種方式。

寫3行程序而不是直接甩下一行int ticks = 491520讓後來讀程序的人摸不到頭腦。有了編譯器的優化,程序員既可以寫出易讀的程序又不必擔心性能受影響。

尤其是在嵌入式領域,很多低端晶元根本就沒有硬體乘法器,如果程序不做上述優化可能這3行代碼需要幾十個cycle,優化過後一個cycle就搞定。

應用編譯優化的級別:

第一級:代碼調整。

代碼調整是一種局部的思維方式;基本上不觸及演算法層級;它面向的是代碼,而不是問題; 所以:語句調整,用匯編重寫、指令調整、換一種語言實現、換一個編譯器、循環展開、參數傳遞優化等都屬於這一級。

第二級:新的視角。

新的視角強調的重點是針對問題的演算法;即選擇和構造適合於問題的演算法。

第三級:表驅動狀態機。

將問題抽象為另一種等價的數學模型或假想機器模型,比如構造出某種表驅動狀態機;這一級其實是第二級的延伸,只是產生的效果更加明顯,但它有其本身的特點。

3. 應用編譯優化三種模式

應用編譯優化三種模式分別是:編譯時間優化模式、執行時間優化模式和代碼大小優化模式。
1、編譯時間優化模式:關注編譯速度的提升,以縮短應用程序高脊的編譯時間為目標。在這種模式下,編譯器會減少編譯時間,會降低應用程序的執行效率。
2、執行時間優化模式:關注應用程序的執行效率,以提高應用程序的性能為目標。在這種模式下,編譯器會優化應用程序的代碼,以提高執行效率,會增加編譯時間。
3、代碼大小優化模式:關注應用程序的大小,以減小應兆培用程序的體積為目標。族念唯在這種模式下,編譯器會減小應用程序的代碼大小,以減小應用程序的體積,會降低應用程序的執行效率。

4. C/C++的編譯器會怎樣優化

優化編譯是一個極其復雜和龐大的問題,不可能就這么說清楚。

簡單說就是凡是有辦法簡化的處理編譯器會盡可能給你簡化,凡是有辦法用SIMD並行的運算編譯器會盡量給你並行,凡是你沒用到的內容編譯器都會給你刪除。

5. 編譯原理 代碼優化的方法有哪些

  1. 最直接有效的就是使用css+div的格式,將網頁中的樣式都放到css中,代碼直接調取相應的css文件

  2. 寫代碼的時候不需要的空格不要留,減小代碼所佔的空間

6. 編譯的代碼優化

代碼優化是指對程序進行多種等價變換,使得從變換後的程序出發,能生成更有效的目標代碼。所謂等價,是指不改變程序的運行結果。所謂有效,主要指目標代碼運行時間較短,以及佔用的存儲空間較小。這種變換稱為優化。
有兩類優化:一類是對語法分析後的中間代碼進行優化,它不依賴於具體的計算機;另一類是在生成目標代碼時進行的,它在很大程度上依賴於具體的計算機。對於前一類優化,根據它所涉及的程序范圍可分為局部優化、循環優化和全局優化三個不同的級別。

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

熱點內容
雲伺服器寬頻單位 發布:2025-02-11 20:48:11 瀏覽:538
安卓數據線公頭是哪個 發布:2025-02-11 20:45:42 瀏覽:812
網址原始密碼是什麼 發布:2025-02-11 20:33:52 瀏覽:72
怎麼創建伺服器我的世界網易 發布:2025-02-11 20:18:36 瀏覽:467
伺服器電腦與客戶端的連接 發布:2025-02-11 20:18:32 瀏覽:36
安卓哪個系統最流暢好用 發布:2025-02-11 20:17:44 瀏覽:879
蘋果平板安卓模擬器哪個好用 發布:2025-02-11 20:17:01 瀏覽:834
手機谷歌伺服器怎麼樣 發布:2025-02-11 20:08:37 瀏覽:221
編譯簡單游戲 發布:2025-02-11 20:02:10 瀏覽:866
php測評系統 發布:2025-02-11 19:42:58 瀏覽:294