Font Size: a A A

Analysis On The Mechanism Of Lua Virtual Machine

Posted on:2016-09-04Degree:MasterType:Thesis
Country:ChinaCandidate:S W WangFull Text:PDF
GTID:2308330461457132Subject:Computer technology
Abstract/Summary:PDF Full Text Request
It has been more than 20 years since Lua was developed by the Catholic University of Brazil. With the rapid development of computer application technology and the continuous improvement of advanced scripting language, Lua can be more easily embedded into applications and provide a flexible extension and customization features for them. Compared with the other similar advanced interpreted scripting languages, Lua has two critical characteristics:simpler and more efficient. Most experiments show that it has higher running efficiency than most other similar scripting languages (such as Python, Perl etc.). Besides, Lua also provides very rich and useful function, such as functional programming (all functions are First-Class value), coroutine, automatic memory management etc. Because lua is written in C, it can interact conveniently with C/C++programs. All these properties attribute to the simplified, clever and efficient design of the Lua virtual machine.It has been quite a long time till Lua 5.0 was released when the register based VM substitutes for the stack based VM. The register based VM reduces the instruction count and the instruction execution overhead of adjusting the stack so that the execution efficiency is improved. The Lua VM’s execution efficiency is relevant not only to the storage structure of the instructions’operand but also to the compilation and interpretation process of the programs. Generally interpretive source code should firstly be compiled into byte code, and then the byte code is interpreted and executed one by one in the interpreter. The interpreter framework designed to execute byte code directly affects the VM execution efficiency. Lua has implemented the simplest design method of interpreter framework (switch case), the switch case method achieves a relatively high efficiency due to the less instruction number of Lua VM. A newer version of Python VM has improved the execution efficiency after adopting a better instruction dispatch mode (token threading). VM with more efficient scheme is more complicated in design and has more memory consumption in implementation. In addition, garbage collection (GC) algorithms also affect the VM’s efficiency in a certain extent. The Lua GC has been optimized with several techniques such as the generational and incremental strategies; however it achieves ordinary performance as compared with other VMs’ GC. This is because that the body of Lua GC is still the ancient mark and sweep algorithm, where both mark and sweep process are time-consuming and the memory utilization is fairly low (more memory fragmentation production), thus leading a slightly poorer performance than the many other VMs. Consequently the Lua GC mechanism urgently needs to be improved.In this paper, we briefly introduce the Lua language characteristic at first; Secondly the implementation of the Lua VM is analyzed, especially the Lua compilation process, thread execution, function calls and GC process are in-depth of inquiry; Then the key technologies of the implementation of the Lua VM and the Python VM are compared, within which why their efficiency are different are explained; Thirdly the implementation of the execution framework and the GC mechanism of the Lua VM are improved, in the execution framework, the old switch case dispatch mode is replaced by the mixture of token threading and super instruction dispatch mode, as of Lua GC, the Sliding Steps Copy algorithm is proposed and applied to the Lua GC; Lastly several groups of experiments are deployed to test the improvement in performance, by comparison and analysis of the experimental results, we have verified the validity and summarized the advantages and disadvantages of the improvements.
Keywords/Search Tags:Lua Virtual Machine, Execution Framework, Efficiency, GC Algorithm
PDF Full Text Request
Related items