部分opcodes Erlang VM 使用的含义很明显,但其他的很神秘,它们之间似乎有细微的差别。
举个例子:
call_ext
有什么区别和 call_ext_only
操作码? allocate
有什么区别和 allocate_zero
操作码? test_heap
操作码用于?它是某种检查还是实际上在堆中分配了一些空间?它以某种方式与元组和列表的使用有关,但在哪些方面呢? allocate
的论据是什么?代表? 如果有人能指出我可用于 opcodes 的任何文档。由 Erlang VM 使用,或者如果他至少能在上述几点上启发我,将不胜感激。
最佳答案
如 similar SO-question 中所述和 the erlang-documentation :
Note that the format of assembler files is not documented, and may change between releases - this option is primarily for internal debugging use.
如果您真的想知道发生了什么,似乎您必须在源代码中进行跟踪。大多数工作是在 erts/emulator/beam/beam_emu.c 中完成的(我已经研究过 otp_src_R15B02):
call_ext
: 设置 continuation pointer到当前指令+2 并调度/调用外部。 call_ext_only
: 不要碰CP,直接 dispatch 。 (~第 1520 行)allocate_zero
还将其初始化为 0x00
(~第 334 行)。 test_heap
: 检查堆的 Nh 个词是否可用;如果没有,请进行垃圾收集。 (~第 390 行)allocate(StackNeeded, NumberOfRegistersToPreserve)
(~第 316 行)整个文件是#defines 和gotos 的组合,一些宏定义在同一文件夹中的ops.tab 中。我也不是 erlang-asm 的专家,可能错过了一些东西。请记住这一点,并在开始与他们合作之前交叉检查我的陈述。
从链接的 SO-awnser 中引用 TamasNagy:
I'm not sure what are you trying to achieve with this, but core erlang might be a better level to do code manipulation.
请在那里查看更多信息。 Erlang 有它的优势,但文档不是其中之一。
问候。
关于Erlang 操作码及其含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13397434/