Erlang JAM二三话

转载请注明,来自:http://blog.csdn.net/skyman_2001

JAM即Joe's Abstract Machine.下面是摘录自http://www.erlang.org/faq/academic.html的关于JAM的说明:

First I designed an abstract machine to execute Erlang. This was called the JAM machine; JAM = Joe's Abstract Machine.

Then I wrote a compiler from Erlang to JAM and an emulator to see if the machine worked. Both these were written in prolog.

At the same time Mike Williams wrote a C emulator for the JAM.

Then I rewrote the erlang-to-jam compiler in Erlang and used the prolog compiler to compile it. The resultant object code was run in the C emulator. Then we threw away prolog.

Some of this is described in an old paper


了解JAM的内部结构对理解Erlang VM很有帮助,Erik Johansson和Christer Jonsson合写的硕士论文《Native Code Compilation for Erlang》里对JAM有比较详细的介绍。这里只捡重要的作为笔记,想详细了解的可以阅读该论文。

1. 寄存器

PC - Pointer to the next instruction  to execute;

STOP - Pointer to the stack top of the active process;

HTOP - Pointer to the heap top of the active process;

ARGS - Pointer to the first argument (on the stack) of the current function;

VARS - Pointer to the first local variable on the stack;

FAIL_PC - Address where execution should continue after a failure;

FAIL_REASON - The reason for the failure;

P - Pointer to the process control block (PCB).

2. 数据表示


3. 代码

The JAM instruction set is implemented with byte codes, making it compact. Code is patched at load time (for example with indexes into the atom table). A module in Erlang is a collection of functions sharing the same name space. Code is loaded one module at the time, when needed.

4. 函数调用


When the function returns, the frame is popped from the stack and the return value is pushed (in the same stack position as the first argument).

5. 并发

每个进程有自己的process control block(PCB), stack和heap。当进程没被执行时,JAM的寄存器存储在PCB中。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值