简体   繁体   English

BEAM和JVM之间有哪些基本的功能/架构差异?

[英]What are some fundamental Feature/Architectural differences between the BEAM and JVM?

What are some fundamental Feature/Architectural difference between the BEAM and JVM? BEAM和JVM之间的一些基本功能/架构差异是什么?

  1. Yes I know: one was originally built around java and the other built around erlang 是的我知道:一个最初是围绕java构建的,另一个是围绕erlang构建的
  2. I understand the JVM (somewhat) and want to compare their structures 我理解JVM(有点)并希望比较它们的结构
  3. For example I know that the JVM has one Global GC and BEAM has one per process 例如,我知道JVM有一个全局GC,BEAM每个进程有一个

First of all, Beam is a register machine, not a stack machine. 首先,Beam是一台注册机,而不是堆栈机。 Like the WAM for Prolog, it uses "X-registers" which are normal registers (implemented as an array in C), and "Y-registers" which are names for slots in the local function activation record (the "call frame") on the stack. 与Prolog的WAM一样,它使用“X寄存器”,它们是普通寄存器(在C中实现为数组),“Y寄存器”是本地功能激活记录中的插槽名称(“调用帧”)在堆栈上。 There are no stack manipulation instructions. 没有堆栈操作指令。

Second, there are instructions for quickly allocating a few more words of heap memory, for initializing tuples and other data structures on the heap, for selecting elements of tuples, etc. JVM is focused on objects, and has a 'new' operation that hides the details of memory allocation and basic initialization. 其次,有快速分配堆内存的几个字,用于初始化堆上的元组和其他数据结构,用于选择元组元素等的指令.JVM专注于对象,并具有隐藏的“新”操作内存分配和基本初始化的细节。

The BEAM has an instruction for decrementing the "reduction counter" for the process and deciding whether it is time to yield to let another process run. BEAM有一条指令,用于递减流程的“减少计数器”,并决定是否需要让另一个流程运行。 JVM on the other hand has synchronization instructions for threads. 另一方面,JVM具有线程的同步指令。

One important difference is that BEAM has tail call instructions, which JVM lacks. 一个重要的区别是BEAM具有JVM缺少的尾调用指令。

Finally, for both the BEAM and JVM, the instruction set used in object files are really only a transport format. 最后,对于BEAM和JVM,目标文件中使用的指令集实际上只是一种传输格式。 The BEAM emulator rewrites the instructions from the file into an internal version with many optimized special-case instructions (that can change from one release to another). BEAM仿真器将文件中的指令重写为内部版本,其中包含许多优化的特殊情况指令(可以从一个版本更改为另一个版本)。 Alternatively, you can compile to native code. 或者,您可以编译为本机代码。 Most JVMs do the same thing. 大多数JVM都做同样的事情。

Some other interesting points are: 其他一些有趣的观点是:

  1. Processes are BEAM citizens and are managed by the VM itself while the JVM delegates their management to the OS. 进程是BEAM公民,由VM本身管理,而JVM将其管理委托给操作系统。 This allows the BEAM to manage (create, delete, context switch, ...) very quickly and, thus, to be able to manage hundreds of thousands of processes versus few hundreds of java threads on a reasonable machine. 这允许BEAM非常快速地管理(创建,删除,上下文切换......),从而能够在合理的机器上管理数十万个进程而不是数百个Java线程。

  2. On BEAM, inter-process communications is based on message exchange which eliminates most if not all situations which may lead to a race condition. 在BEAM上,进程间通信基于消息交换,消除了大多数(如果不是所有)可能导致竞争条件的情况。 On Java, you need to synchronize threads which is difficult and bug prone. 在Java上,您需要同步很难且容易出错的线程。

  3. One important point is that garbage collection is done on a per process basis in the BEAM while it's a global process in the JVM. 一个重要的一点是,垃圾收集是在BEAM中基于每个进程完成的,而它是JVM中的全局进程。 The impact is that a GC on the JVM may freeze the whole VM for possibly some seconds while on the BEAM each process has to give some of it's execution operations (reductions) to the GC without impact on the other processes. 影响是JVM上的GC可能冻结整个VM可能会持续几秒钟,而在BEAM上,每个进程必须向GC提供一些执行操作(减少),而不会影响其他进程。

Recently, some new libraries like VertX (I don't really know Akka but I believe it's the case) for JVM languages began to implement similar process behaviours to attempt to solve issues 1. and 2. I believe the problem of the GC cannot be solved with simplicity with a library, though. 最近,一些像VertX这样的新库(我真的不知道Akka,但我相信是这种情况)对于JVM语言开始实现类似的过程行为来尝试解决问题1.和2.我认为GC的问题不可能是尽管如此,通过图书馆简化了解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular 2与Angular 4与Angular 5之间的架构差异是什么? - What are the architectural differences between Angular 2 vs Angular 4 vs Angular 5? 架构模式和架构风格有什么区别? - What's the difference between Architectural Patterns and Architectural Styles? 架构驱动因素/因素与架构重要要求之间有什么区别 - What is the difference between Architectural drivers/factors and architectural significant requirements 设计模式、架构模式、架构风格和架构之间有什么区别? - What's the difference between Design pattern, Architectural pattern, Architectural style, and Architecture? 架构视图,观点和视图之间有什么区别? - What’s the difference between Architectural views, viewpoints and views? 架构风格和架构模式的区别 - Difference between architectural styles and architectural patterns 您在云计算设计中遇到了哪些架构问题? - What are some architectural issues you have faced in cloud-focused designs? 这两种线程化方法有什么区别? - What are the differences between those two approaches of threading? 在设计像Stack Overflow这样的基于点的权限系统时,需要考虑哪些体系结构最佳实践? - What are some architectural best practices to consider when designing a point-based permissions system like Stack Overflow uses? 一些架构模式的简单代码实现 - Simple code implementation of some architectural patterns
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM