`
mryufeng
  • 浏览: 982470 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

inside-beam-erlang-virtual-machine

阅读更多
转自: http://erlangdotnet.net/2007/09/inside-beam-erlang-virtual-machine.html

OTP R11B-5 includes more than one million lines of Erlang. The kernel and standard library are about a third of these lines. The emulator, BEAM, is around 200,000 lines of C.

BEAM's C main functions are platform-specific and live in erts/emulator/sys/unix, win32, and so on. (Windows actually has two mains: a simple one similar to the Unix entrypoints in erl_main.c, and a more complex one in erl_main_sae.c which is used in bootstrapping the toolchain.) The conventional mains immediately call erl_start which processes command line arguments, copies argv into a list of strings, creates a process and runs otp_ring0 with the argument list. otp_ring0 looks up and runs init:boot/1. There is more initialization after this, but from otp_ring0 on, apart from some built-in functions, Erlang is implemented in Erlang.

In practice, the Erlang compiler (another 30,000 lines of Erlang) compiles Erlang to BEAM bytecodes. When erl_start runs otp_ring0 and so on, it is loading BEAM binaries generated by the Erlang compiler earlier. The BEAM instruction set is register-based and has 130 instructions. These include instructions for arithmetic, comparsions and boolean logic; manipulating strings, tuples and lists; stack and heap allocation and freeing; type tests for Erlang primitives (numbers, lists, process IDs, references, and so on);  jumps, structured exception handling, and calls and returns; sending messages and reading from the process' mailbox; waiting and timeouts; and so on. The instructions are listed in lib/compiler/src/beam_opcodes.erl. In BEAM, erts/emulator/beam/ops.tab contains rewrite rules that map typed BEAM instructions into emulator internals. A Perl script (beam_makeops) translates this file into C code (mostly macros.)

Some Erlang built-in function (BIFs) calls are translated into an extended instruction set not generated by the compiler. For example, the BIF erlang:self/3 is rewritten as a single 'self' instruction. Other BIF linkage is via a set of instructions for calling BIFs of varying arities. erts/emulator/beam/bif.tab maps BIF labels into C externs. For example, calls to the BIF erlang:spawn/3 boil down to a call to spawn_3 (found in erts/emulator/bif.c), which in turn thunks to erl_create_process.

Incidentally, processes are not related to threads or operating system processes. Instead, BEAM maintains queues of processes that are scheduled to run. There is one queue per priority level. Schedulers pick processes from the queues and run them. Processes maintain their registers and a pointer to the next instruction to execute.

The garbage collector, in erts/emulator/beam/erl_gc.c, is a mark-and-sweep copying collector. The most interesting thing about the BEAM garbage collector is that the garbage collected heaps are per-process. BEAM can do this because Erlang processes communicate explicitly via messages, and not via mutating shared memory. The CLR, in contrast, divides heaps into generations protected by write barriers and does incremental collection to avoid having to garbage collect all of a program's heap at the same time. This extra complexity is part of the price of using a shared heap to communicate between threads in the CLR.

虽然版本比较老 现在是R12B-5不过关键东西还是差不多没变。

分享到:
评论

相关推荐

    rabbitmq-server-3.8.3.exe和erlang22.2.exe 64位压缩文件

    "erlang新版本"则强调了Erlang更新的重要性,因为RabbitMQ的运行依赖于Erlang环境,所以Erlang的更新通常伴随着RabbitMQ的更新。 在压缩包的文件名称列表中,"otp_win64_22.2.exe"是Erlang OTP 22.2版本的Windows ...

    rabbitmq-server-3.8.9-1+erlang-23.1.1+socat-1.7.3.2

    在CentOS7上安装Erlang,你需要下载提供的`erlang-23.1.1-1.el7.x86_64.rpm`包,然后通过`rpm`命令进行安装: ```bash sudo rpm -ivh erlang-23.1.1-1.el7.x86_64.rpm ``` 安装完成后,你可以通过`erl`命令来验证...

    Erlang-Formula.zip_Erlang B _Erlang-B_erlang_erlang B计算_erlang C

    Erlang B 和 Erlang C 是在电信领域中广泛使用的两个数学公式,用于预测和管理电话交换系统的呼叫处理能力。这两个公式由丹麦工程师 Agner Krarup Erlang 在20世纪初开发,对于理解通信系统中的呼叫占用率、阻塞率和...

    rabbitmq-server-3.10.0-1+erlang-23.3.4.11+socat-1.7.3.2

    linux CentOs7 下安装RabbitMq所需文件 rabbitmq-server-3.10.0-1+erlang-23.3.4.11+socat-1.7.3.2 亲自测试 可以使用

    rabbitmq-server-3.8.2和erlang22.2.zip

    rabbitmq是实现了高级消息队列协议(AMQP)的开源消息代理软件,RabbitMQ服务器是用Erlang语言编写的,安装rabbitmq需要安装Erlang开发环境,rabbitmq-server-3.8.2和erlang22.2,最新的rabbitmq是3.8.2版本,只有22...

    rabbitmq-server-3.7.7和erlang21.0.1.zip

    rabbitmq是实现了高级消息队列协议(AMQP)的开源消息代理软件,RabbitMQ服务器是用Erlang语言编写的,安装rabbitmq需要安装Erlang开发环境,rabbitmq-server-3.7.7和erlang21.0.1

    vim-erlang-runtime, Vim的Erlang缩进和语法.zip

    vim-erlang-runtime, Vim的Erlang缩进和语法 用于Vim的Erlang缩进和语法这是 Vim ( 来自 Vim 7.4 ) 附带的Erlang缩进和语法。安装方法 1克隆这里存储库: $ mkdir -p ~/.vim/bundle $ cd ~/.vim/b

    Erlang-or-java.rar_erlang

    标题中的“Erlang-or-java.rar_erlang”表明这是一个关于Erlang和Java之间通信的示例项目。Erlang是一种面向并发、分布式、容错的编程语言,常用于构建高可用性和高并发性的系统,而Java则是一种广泛应用的通用编程...

    Erlang程序设计(中文版-完整书签)&Erlang编程指南(中英文版)

    Erlang程序设计(中文版-完整书签)&Erlang编程指南(中英文版)

    esl-erlang-25.0.3-1-centos-7-amd64.rpm erlang-25.0.3-1 rpm

    esl-erlang_25.0.3-1_centos_7_amd64.rpm erlang_25.0.3-1 rpm用于rabitmq基础环境安装

    testing-erlang-book, 在测试Erlang时,public 书.zip

    testing-erlang-book, 在测试Erlang时,public 书 测试 Erlang我已经创建了一本关于使用QuickCheck和Erlang的新书,你可以在这里找到 http://www.erlang-quickcheck-book.com/。关于本书Erlang已经经存在很长一段...

    rabbitmq-3.9.7-1&erlang-24.0.3&socat-1.7.3.2.rar

    在给定的压缩包"rabbitmq-3.9.7-1&erlang-24.0.3&socat-1.7.3.2.rar"中,包含的是RabbitMQ、Erlang和socat这三个软件的安装包。RabbitMQ是一个流行的开源消息代理和队列服务器,Erlang是支持并发处理和分布式计算的...

    Server Metaprogramming Ruby-Pyton-Groovy-Haskell-Erlang.pdf

    ### 服务器元编程:Ruby、Python、Groovy、Haskell 和 Erlang #### 知识点一:元编程概述 **元编程**是一种程序设计技术,它允许程序在运行时检查自身结构,并能够修改自己的行为或生成新的代码。元编程在多种编程...

    rabbitmq-server-3.8.4 + esl-erlang_23.0_windows_amd64.zip

    标题中的“rabbitmq-server-3.8.4 + esl-erlang_23.0_windows_amd64.zip”指的是RabbitMQ服务器的3.8.4版本与Erlang编程语言的23.0版本的Windows AMD64位版的组合安装包。这个压缩文件是为在基于AMD64架构的Windows...

    2018-FL+erlang语言-Functional Federated Learning in Erlang (ffl-er

    Functional Federated Learning in Erlang (ffl-erl)是一种基于Erlang编程语言实现的分布式机器学习框架,专门针对Federated Learning(联邦学习)设计。联邦学习是一种新兴的机器学习方法,它允许在不集中收集数据...

    erlang_版本24.3.4.4

    - **BEAM虚拟机**:Erlang的运行时系统,全称是BIFs (Built-In Functions)、Erlang、Assembler and Memory管理器。 - **OTP行为**:如Supervisor(监督者)、GenServer(通用服务器)、GenEvent(事件处理器)等,...

    rabbitmq-server-3.8.8+erlang-21.3-1.el7.x86-64-linux版.zip

    在提供的文件“erlang-21.3-1.el7.x86_64.rpm”中,包含了Erlang的21.3版本,适用于EL7系列的Linux发行版,如CentOS或Red Hat。 接下来是RabbitMQ的核心部分——"rabbitmq-server-3.8.8-1.el7.noarch.rpm"。这是...

    rabbitmq-server-3.7.9+ErLang.zip

    ErLang安装是运行RabbitMQ的前提,因为它提供了RabbitMQ运行所需的Erlang虚拟机(BEAM)。在安装这个文件之前,请确保你的操作系统是64位,并且满足ErLang的系统需求。安装过程中,你需要按照向导的提示进行,通常...

    vim-erlang-compiler:Vim的Erlang语法检查和编译器插件

    vim-erlang-编译器vim-erlang-compiler是Vim的Erlang语法检查和编译器插件。目录安装Vim的内置软件包管理器如果您至少使用Vim 8并且不使用其他软件包管理器,则这是推荐的安装方法。 有关Vim内置软件包管理器的信息...

    Erlang-B-Calculator.zip_erlang B calculator

    Erlang-B计算器是一款基于Java编程语言在Eclipse开发环境中实现的应用程序,专门用于计算通信系统中的爱尔兰B公式。爱尔兰B公式是电信领域中用来预测电话交换机或网络拥塞情况的重要工具。这个计算器不仅提供了核心...

Global site tag (gtag.js) - Google Analytics