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 【阅读原文】。感谢您的支持!

您可能感兴趣的

【最新最全】为 iOS 和 Android 的真机和模拟器编译 Luajit 库... 编译 Luajit 库,的确是一个挑战。因为官网的教程,在当前版本的 Xcode 和 NDK 环境中,已经不适用了。以前只是编译了适用于真机的 Luajit 库。最近在尝试编译模拟器 Luajit 库,就顺便梳理了下 Luajit 库的编...
wav2letter: FAIR’s automatic speech recognition to... wav2letter wav2letter is a simple and efficient end-to-end Automatic Speech Recognition (ASR) system from Facebook AI ...
Tools for 2017: LuaJIT, DynASM, R, Nix, Pharo Here is a little braindump on the programming tools I am excited about using in 2017 for my ongoing Snabb hacking. ...
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: #define NULL ((void*...
Android 嵌入 LuaJIT 的曲折道路 相关链接: Windows 下编译 LuaJIT 懒人与伸手党可以直接看最底部。 为什么使用 LuaJIT Lua 官方版的编译嵌入相对简单,但是为什么要用 LuaJIT 呢?我所了解到的优势有: 更高的运行...