[Erlang 0129] Erlang 杂记 VI
把之前阅读资料的时候记下的东西,整理了一下.
Adding special-purpose processor support to the Erlang VM
P23 简单介绍了Erlang Compiler和Beam文件格式;
The Erlang Compiler in short 章节提到了 Core Erlang 这个之前有提到过:
[Erlang 0120] Know a little Core Erlang
http://www.cnblogs.com/me-sa/p/know_a_little_core_erlang.html
Erlang Beam Format
Python module to parse Erlang BEAM files.
https://github.com/matwey/pybeam
P26 3.4 The Erlang Virtual Machine
Joe Armstrong设计的JAM是Stack based machine,现在的BEAM是register based machine.
Beam Loader的章节,解决了之前的很多困惑:
BEAM Loader作为VM的一部分其职责就是加载BEAM文件中的代码.BEAM文件使用的是所谓有限指令集( limited instruction set),这一指令集会在运行时由BEAM Loader展开为扩展指令集(extended instruction set).使用两种指令集的原因是让BEAM文件小一点; BEAM加载逻辑在beam_load.c文件中完成,emulator使用beam_opcodes.c文件中的load scripts将有限指令集转换成为扩展指令集;Perl脚本beam_makeops读取文件ops.tab作为输入生成beam_opcodes.c文件.有限指令集在genop.tab.
上面提到的文件所在路径:
beam_makeops erts/emulator/utils/ ops.tab erts/emulator/beam/ beam_opcodes.c erts/emulator/<machine>/opt/smp/ beam_load.c erts/emulator/beam/ genop.tab lib/compiler/src/
文件beam_opcodes.c是在Erlang编译期生成的.
这也就是小消息大运算背后的原因.
@cnDenis 提到的霸爷的文章 量化Erlang进程调度的代价
Heap Architectures for Concurrent Languages using Message Passing
地址: http://www.fantasi.se/publications/ISMM02.pdf
摘要: We describe how interprocess communication and garbage collection happens in each architecture, and extensively discuss the tradeoffs that are involved. In an implementation set-
ting (the Erlang/OTP system) where the rest of the runtime system is unchanged, we present a detailed experimental comparison between these architectures using both synthetic programs and large commercial products as benchmarks.
备注: 一句话总结这篇论文就是:当消息传递的时候本质上发生了什么
P3
Stack用来存放function arguments, return addresses, and local variables.复合数据结构(Compound terms)比如 lists, tuples, 以及超过一个机器字长的浮点数或者bignums都会在heap存放.stack和heap向对方区域增长,这样做的好处是很容易做溢出检测,只要比较一下stack和heap的指针即可,这样设计的缺点是stack或heap的一个内存区域的重新分配会同时影响stack和heap两块区域.Erlang还支持大块的二进制数据,这种数据不是在heap存储而是在单独的全局内存区域存储并进行引用计数.
消息传递是通过拷贝完成的,从sender的heap拷贝到receiver的heap;然后把指向这个消息的指针插入到receiver的mailbox,mailbox包含在进程的PCB内.下面的图


P1进程内有一些共享的数据部分在拷贝的过程中会被展开,这种情况下拷贝之后的消息就要比之前的消息占用更大空间,这种情况实际情况很少发生.这种情况是可以通过跟踪手段(marking technique)和转向指针( forwarding pointers)来规避,但是这样可能让消息通信更慢.
关于forwarding pointer的资料:
http://www.memorymanagement.org/glossary/f.html#glossary-f
forwarding pointer
Some garbage collectors move reachable objects into another space. They leave a forwarding pointer, a special reference pointing to the new location, in the old location.
The following difference between the two memory architectures also deserves to be mentioned: In a process-centric system, it is easy to impose limits on the space resources that a particular (type of) process can use. Doing this in a shared heap system is significantly more complicated and probably quite costly. Currently, this ability is not required by Erlang.
Efficient memory management for concurrent programs that use message passing I,II
地址: http://user.it.uu.se/~kostis/Papers/scp_mm.pdf
备注: 这其实是一个论文集
P13 1.3 Improving message passing
In the private heap architecture, the send operation consists of three parts:
1. Calculate the size of the message to allocate space in the receiver’s heap;
2. copy the message data to the receiver’s heap; and finally,
3. deliver the message to the receiver’s message queue.
To reduce the complexity of the send operation, we want to remove the parts of the send whose cost is proportional to the message size, namely 1 and 2. By introducing a new memory architecture, where all process-local heaps are replaced by a shared memory area, we can achieve this and reduce the cost of sending messages to O(1), that is, make it a constant time operation. We call this the shared heap architecture.
An introduction to Core Erlang
地址: http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=1C8691982F56D28905DAC4D731A386C7?doi=10.1.1.20.7146&rep=rep1&type=pdf
备注: 简单描述Core Erlang 和Erlang的关系,发展历史 从Erlang代码到Core Erlang代码中间经历的分析和转换过程中是怎样被大大简化的.
这个之前有详细了解过, [Erlang 0120] Know a little Core Erlang http://www.cnblogs.com/me-sa/p/know_a_little_core_erlang.html
[Erlang 0078] Erlang HiPE 二三事 http://www.cnblogs.com/me-sa/archive/2012/10/09/erlang_hipe.html

1> c(my module, [native]).
compile:file(my module, [native])
erlc +native my module.erl
erlc +native +’{hipe,[verbose]}’ my module.erl
Generating native code and loading it on-the-fly into the system is possible even in cases when the Erlang source code is not available but the .beam file (containing BEAM bytecode) exists. This can be done for whole modules using:
hipe:c(my module)
hipe:c({M,F,A}).
3> c(my module, [native, {hipe, [verbose, o3]}]).
c(my module, [native, core]). %% Compilation from Core Erlang
警告:
Do not use the -compile(export_all) directive. This reduces the likelihood of functions being inlined, and makes useful type analysis impossible.
[Erlang 0129] Erlang 杂记 VI的更多相关文章
- [Erlang 0124] Erlang Unicode 两三事 - 补遗
最近看了Erlang User Conference 2013上patrik分享的BRING UNICODE TO ERLANG!视频,这个分享很好的梳理了Erlang Unicode相关的问题,基本 ...
- [Erlang 0122] Erlang Resources 2014年1月~6月资讯合集
虽然忙,有些事还是要抽时间做; Erlang Resources 小站 2014年1月~6月资讯合集,方便检索. 小站地址: http://site.douban.com/204209/ ...
- [Erlang 0105] Erlang Resources 小站 2013年1月~6月资讯合集
很多事情要做,一件一件来; Erlang Resources 小站 2013年1月~6月资讯合集,方便检索. 小站地址: http://site.douban.com/204209/ ...
- Erlang 103 Erlang分布式编程
Outline 笔记系列 Erlang环境和顺序编程Erlang并发编程Erlang分布式编程YawsErlang/OTP 日期 变更说明 2014-11-23 A Outl ...
- [Erlang 0057] Erlang 排错利器: Erlang Crash Dump Viewer
http://www.cnblogs.com/me-sa/archive/2012/04/28/2475556.html Erlang Crash Dump Viewer真的是排错的天兵神器,还记得我 ...
- [Erlang 0118] Erlang 杂记 V
我在知乎回答问题不多,这个问题: "对你职业生涯帮助最大的习惯是什么?它是如何帮助你的?",我还是主动回答了一下. 做笔记 一开始笔记软件做的不好的时候就发邮件给自己, ...
- [Erlang 0123] Erlang EPMD
epmd进程和Erlang节点进程如影随形,在Rabbitmq集群,Ejabberd集群,Couchbase集群产品文档中都会有相当多的内容讲epmd,epmd是什么呢? epmd 是Erlan ...
- [Erlang 0119] Erlang OTP 源码阅读指引
上周Erlang讨论群里面提到lists的++实现,争论大多基于猜测,其实打开代码看一下就都明了.贴出代码截图后有同学问这代码是哪里找的? "代码去哪里找?",关于Erla ...
- [Erlang 0114] Erlang Resources 小站 2013年7月~12月资讯合集
Erlang Resources 小站 2013年7月~12月资讯合集,方便检索. 附 2013上半年盘点: Erlang Resources 小站 2013年1月~6月资讯合集 小站地 ...
随机推荐
- ASP.NET MVC Model元数据(二)
ASP.NET MVC Model元数据(二) 前言 在上篇中,给大家留个对Model元数据的印象,并没有对Model元数据有过多的讲解,而在本篇中也不会对Model元数据的本身来解释,而是针对于它的 ...
- [Javascript] 爬虫 模拟新浪微博登陆
概述: 由于业务需要,要编写爬虫代码去爬去新浪微博用户的信息. 虽然在网上能找到不少信息,但由于新浪微博改版,其登陆机制进行了修改,故很多老的文章就不适合用了. 经过一番摸索,成功模拟新浪微博的登陆 ...
- SQL Server 阻止了对组件“xp_cmdshell”的 过程“sys.xp_cmdshell”的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。
今天在创建数据库的时候突然发现,xp_cmdshell的存储过程不能用了,网上一搜,发现大部分都是只关闭安全配置,然后就有了下文 代码:具体的看注释,值得一提的是==>reconfigure w ...
- 【.net深呼吸】(WCF)OperationContextScope 的用途
一个WCF服务可以实现多个服务协定(服务协定实为接口),不过,每个终结点只能与一个服务协定关联,并指定调用的唯一地址.那么,binding是干吗的?binding是负责描述通信的协议,以及消息是否加密 ...
- 文本比较算法:Needleman/Wunsch算法
本文介绍基于最长公共子序列的文本比较算法——Needleman/Wunsch算法.还是以实例说明:字符串A=kitten,字符串B=sitting那他们的最长公共子序列为ittn(注:最长公共子序列不 ...
- CRL快速开发框架系列教程二(基于Lambda表达式查询)
本系列目录 CRL快速开发框架系列教程一(Code First数据表不需再关心) CRL快速开发框架系列教程二(基于Lambda表达式查询) CRL快速开发框架系列教程三(更新数据) CRL快速开发框 ...
- 如何修复VUM在客户端启用之后报数据库连接失败的问题
在上一篇随笔中介绍了关于重新注册VMware Update Manager(VUM)至vCenter Server中的方法,最近有朋友反应,原本切换过去好好的更新服务为什么某次使用一下就不灵了? 当时 ...
- 数据结构笔记--二叉查找树概述以及java代码实现
一些概念: 二叉查找树的重要性质:对于树中的每一个节点X,它的左子树任一节点的值均小于X,右子树上任意节点的值均大于X. 二叉查找树是java的TreeSet和TreeMap类实现的基础. 由于树的递 ...
- 读书笔记--SQL必知必会15--插入数据
15.1 数据插入 使用INSERT语句将行插入(或添加)到数据库表.可能需要特定的安全权限. 插入完整的行 插入行的一部分 插入某些查询的结果 15.1.1 插入完整的行 要求指定表名和插入到新行中 ...
- windows环境tomcat8配置Solr5.5.1
前言 前前后后接触Solr有一个多月了,想趁着学习Solr顺便把java拾起来.我分别用4.X和5.X版本在windows环境下用jetty的方式.tomcat部署的方式自己搭建了一把.其中从4.x到 ...