Code reading: LuaJIT

综合编程 2016-02-17

I have started reading LuaJIT sources. I like the fact that the source code is compact and it is reasonable to print and read a whole file (or read it an iPad with iOctocat
).

The parts I am reading now are theprofiler, thedumper, and thetrace assembler. I have a basic mental model of tracing JITs from Thomas Schilling's thesis
.

I have a few interests here:

  1. I would like to have a stronger mental model of the data structures involved. How is the Intermediate Representation stored in memory? Is it ephemeral or persistent? How much cross-referencing information is available between the representations: could you generate an interleaved listing of the IR and the machine code for example? (source too?) I am accustomed to knowing these kind of details from other languages like Forth, Lisp, and Smalltalk, but I haven't dug down to that level of LuaJIT yet.
  2. Does the assembler really assemble backwards from the last IR instruction? (If so then does each IR instruction assembler emit the machine code backwards too?)
  3. How can I always have a visceral feeling for how my code is executing on the CPU? Currently it takes me quite a bit of manual legwork to analyze program behavior: dump traces to a file, profile to see which traces are relevant, stare at the traces to see which code they are related too, and so on. I would love to have this much more streamlined e.g. for the profiler to automatically show me an interleaved IR/machinecode dump of all traces using >= 5% CPU with annotations on the hotspots. This is the kind of thing that is quite transparent in perf top
    when programming in C.
  4. I would like to have a better feeling for what makes LuaJIT happy, what makes it sad, and what makes it unpredictable. I want to really see in the generated code what are the consequences of things like unpredictable branches within loops. I am sure that I could adapt my programming style to be better suited to the compiler but this has to be driven by a better understanding of the compiler rather than following "do this, don't do that" lists of program optimization rules.

Generally I am very enthusiastic about LuaJIT. I do see it as a technology in the tradition of Lisp, Forth, and Smalltalk: one that is intellectually rewarding to study and use. I look forward to spending a lot more time with it.

责编内容by:lukego (源链)。感谢您的支持!

您可能感兴趣的

Android 嵌入 LuaJIT 的曲折道路 相关链接: Windows 下编译 LuaJIT 懒人与伸手党可以直接看最底部。 为什么使用 LuaJIT Lua 官方版的编译嵌入相对简单,但是为什么要用 LuaJIT 呢?我所了...
NULL is equal to 0 in C, so do I treat b... Afaik NULL can be (or really is, at least in my stdlib implementation) #define 'd as: ...
wav2letter: FAIR’s automatic speech recognition to... wav2letter wav2letter is a simple and efficient end-to-end Automatic Speech Recognition (ASR) syst...
用好Lua+Unity,让性能飞起来—LuaJIT性能坑详解... 导语:大家都知道LuaJIT比原生Lua快,快在JIT这三个字上。但实际情况是,LuaJIT的行为十分复杂。尤其JIT并不是一个简单的把代码翻译成机器码的机制,背后有很多会影响性能的因素存在...
Comparing the C FFI Overhead of Various Languages ffi-overhead comparing the c ffi overhead on various programming languages Requirements: ...