Dart的快照和Java字节码有什么区别? [英] What is the difference between Dart's snapshots and Java bytecode?

查看:450
本文介绍了Dart的快照和Java字节码有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在读Dart快照,他们经常与Smalltalk图像进行比较。但对我来说,他们听起来像Java字节码。

I've been reading up on Dart snapshots, and they're frequently compared to Smalltalk images. But to me, they sound alot like Java bytecode.

例如:

快照不是正在运行的程序的快照,它是在令牌变成机器代码之前生成的,因此,快照中没有捕获到程序状态。

"A Dart snapshot is just a binary serialization of the token stream, generated from parsing the code. A snapshot is not a "snapshot of a running program", it's generated before the tokens are turned into machine code. So, no program state is captured in a snapshot."

它们是跨平台的:

快照格式本身是跨平台的,在32位,64位机器之间工作,这种格式已经做到了,它快速读入内存,强调最小化额外的工作,如指针修复。

"The snapshot format itself is cross-platform meaning that it works between 32-bit, 64-bit machines and so forth. The format has been made so that it's quick to read into memory with a emphasis on minimizing extra work like pointer fixups."

我在某处出错了吗?

资料来源:

在dart中的快照概念是什么?

http://www.infoq.com/articles/google-dart

推荐答案

快照包含以类似于Smalltalk图像的序列化形式表示加载脚本的VM数据结构。为了更好地了解快照中包含的内容,我们应该看看Dart VM在读取脚本时创建的内容:

Snapshots contain the VM data structures representing the loaded script in a serialized form similar to Smalltalk images. To get a better understanding of what is contained in the snapshot, we should take a look at what the Dart VM creates as it reads the script:


    <
  • 类对象,包含描述所有方法和字段的所有对象。

  • 表示所有加载的源代码的脚本和Tokenstream对象。

  • 源代码中所有使用的标识符和字符串常量的字符串对象。

  • Library objects, referring to all top-level structures such as classes or top-level methods and variables.
  • Class objects, containing all objects describing all methods and fields.
  • Script and Tokenstream objects representing all loaded source code.
  • String objects for all used identifiers and string constants in the source code.

使用架构不可知的格式生成快照时,此对象图被序列化为文件。这允许Dart VM在32位或64位计算机上反序列化此快照文件,并且比从一组文件中读取原始脚本更快地重新创建所有必需的内部VM数据结构(参见John的回答)。

This object graph is serialized into a file when generating a snapshot using a format that is architecture agnostic. This allows the Dart VM to deserialize this snapshot file on 32-bit or 64-bit machines and recreate all of the necessary internal VM data structures much quicker than reading the original scripts from a set of files (see John's answer).

为了澄清约翰的回答。生成快照时,Dart VM不会解析所有源代码。它只需要解析源的顶层,以便能够提取类,方法和字段定义,因为它们在序列化图表中表示。特别是方法体不被解析,并且由于脚本语言的惯例,只有当控制到达特定方法时才报告错误。

To clarify John's answer a bit. The Dart VM does not parse ALL of the source code when generating the snapshot. It only needs to parse the top level of the sources to be able to extract class, method and field definitions as these are represented in the serialized graph. In particular method bodies are not parsed and as it is customary for a scripting language errors will be only reported once control reaches the particular method.

Java字节码的目的是完全不同为Ladicek指出。

The purpose of Java bytecodes is entirely different as Ladicek points out. You could create a snapshot of the VM data structures in a JVM once the bytecodes are loaded to get a similar effect.

简而言之:快照包含所有字节的高效表示形式

In short: The snapshot contains an efficient representation of all the data structures allocated on the Dart VM heap which are needed to start executing the script.

-Ivan

这篇关于Dart的快照和Java字节码有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆