Artificial Intelligence Programming Lab(AIPLab) 討論區

97學年(上)課程2008Autumn => 編譯器 => 主題作者是: wei81 於 一月 07, 2009, 12:27:37 am



主題: [期末報告]-Escape analysis->95441050
作者: wei81一月 07, 2009, 12:27:37 am
資工3C 95441050 魏振原

第三類Compiler issues
Escape analysis

 
In programming language compiler optimization theory, escape analysis is a method for determining the dynamic scope of pointers. It is related to pointer analysis and shape analysis.

When a variable (or an object) is allocated in a subroutine, a pointer to the variable can escape to other threads of execution, or to calling subroutines. If a subroutine allocates an object and returns a pointer to it, the object can be accessed from undetermined places in the program — the pointer has "escaped". Pointers can also escape if they are stored in global variables or other data structures that, in turn, escape the current procedure.

Escape analysis determines all the places where a pointer can be stored and whether the lifetime of the pointer can be proven to be restricted only to the current procedure and/or thread.

Optimizations
A compiler can use the results of escape analysis as basis for optimizations:
Converting heap allocations to stack allocations. If an object is allocated in a subroutine, and a pointer to the object never escapes, the object may be a candidate for stack allocation instead of heap allocation.
Synchronization elision. If an object is found to be accessible from one thread only, operations on the object can be performed without synchronization.
Breaking up objects or scalar replacement. An object may be found to be accessed in ways that do not require the object to exist as a sequential memory structure. This may allow parts (or all) of the object to be stored in CPU registers instead of in memory.

Practical considerations
In object-oriented programming languages dynamic compilers are particularly good candidates for performing escape analysis. In traditional static compilation method overriding can make escape analysis impossible, as any called method might be overridden by a version that allows a pointer to escape. Dynamic compilers can perform escape analysis using the available information on overloading, and re-do the analysis when relevant methods are overridden by dynamic code loading.

Escape analysis has been a target of interest in particular due to the Java programming language. Java's combination of heap-only object allocation, built-in threading, and the Sun HotSpot dynamic compiler creates a candidate platform for escape analysis related optimizations (see Escape analysis in Java). Escape analysis is implemented in Java Standard Edition 6.

資料來源:
http://en.wikipedia.org/wiki/Escape_analysis

加分題:
Pascal
Pascal是種高階的程式語言,由瑞士蘇黎士理工學院的尼古拉斯·沃斯(Niklaus Wirth)教授於1960年末期所設計,ISO對Pascal進行修改以後,形成了標準Pascal語言。

Pascal語言還是一種自編譯的語言,這就使它的可靠性大大提高了。在Pascal的各個版本中,經典編譯器中尤以Turbo Pascal的功能最為強大,在當今普遍認為Free Pascal的功能更加強大。

Pascal具有簡潔的語法,結構化的程序結構。它是結構化編程語言,于70年代在ALGOL基礎上研製出來的。它具有豐富的數據類型並提供了數據類型定義設施,其控制結構體現了結構程序設計原則。

它最初是為系統地教授程序設計而設計的,特點是簡明化和結構化,適合教學科學計算與系統軟體的研製。如今,在許多學校的計算機語言課上,學的都是Pascal語言,用的都是Turbo Pascal。至今,Pascal還是國際信息學奧林匹克競賽中最受歡迎的程式語言之一。

Pascal是最早出現的結構化程式語言,具有豐富的數據類型和簡潔靈活的操作語句,適於描述數值和非數值的問題。

美國Borland公司于1983年推出了Turbo Pascal編譯器。其後發展了Object Pascal,作為其Delphi開發工具的開發語言。 Kylix是Borland公司Pascal產品的新成員,支持Delphi和C/C++,運行於Linux。

其他Pascal編譯器
Free Pascal [1] 原名 FPK Pascal,是一個 32 bit 的 Pascal 編譯器(現在亦可執行於64-bit的系統),採用GNU通用公共許可證,可運行於多個平臺,支持 Delphi 的語法。它是用 Pascal 寫成的。包含Turbo Pascal、Delphi等的兼容模式。是中國現在信息學奧林匹克競賽中的Windows下推薦編譯器之一。
GNU Pascal Compiler (GPC)是GNU Compiler Collection (GCC)的一員,用C寫成。
P4 compiler

批評
很多人認為Pascal不適合開發大程式。在八十年代,Pascal非常流行,許多重要的程式如Apple Lisa和Macintosh,都使用Pascal開發。Brian Kernighan,C編程語言的發明者之一,在他的文章「Why Pascal Is Not My Favorite Programming Language」(「為什麼Pascal不是我最喜愛的程式語言」)批評了當時Pascal的種種缺點。 事實上,隨著Pascal的不斷發展,他的論點已經不能符合現在的Pascal編譯器。
資料來源:
http://zh.wikipedia.org/wiki/Pascal


主題: 回覆: [期末報告]-Escape analysis->95441050
作者: admin一月 15, 2009, 02:28:58 pm
OK!14