What’s the difference between DART’s snapshot and Java bytecode?

I've been reading dart snapshots, which are often compared with Smalltalk images But to me, they sound like Java bytecode

For example:

"Dart snapshot is just a binary serialization of token stream and is generated by parsing code. Snapshot is not" snapshot of running program ", it is generated before token is converted to machine code. Therefore, no program state is captured in snapshot“

And they are cross platform:

"The snapshot format itself is cross platform, which means that it can work between 32-bit and 64 bit machines, etc. the format has been completed, so it can be quickly read into memory, and emphasizes the extra work of minimizing pointer correction“

Did I make a mistake somewhere?

Source: what is the snapshot concept in dart? http://www.infoq.com/articles/google-dart

Solution

The snapshot contains the VM data structure representing the loading script, and its serialization form is similar to the Smalltalk image In order to better understand the contents contained in the snapshot, we should look at the contents created by dart VM when reading the script:

>Library objects refer to all top-level structures, such as classes or top-level methods and variables. > Class object, including all objects that describe all methods and fields. > Scripts and tokenstream objects represent all loaded source code. > All identifiers and string constants used in the source code are string objects

When a snapshot is generated in a schema independent format, this object graph is serialized into a file This allows dart VM to deserialize this snapshot file on a 32-bit or 64 bit machine and recreate all necessary internal VM data structures much faster than reading the original script from a set of files (see John's answer)

To clarify John's answer When a snapshot is generated, dart VM will not parse all source code It only needs to parse the top level of the source to extract class, method and field definitions, because they are represented in the serialization diagram In particular, the method body is not parsed, and due to the Convention of scripting language, once the control reaches a specific method, only errors will be reported

As ladicek points out, the purpose of Java bytecode is completely different Once the bytecode is loaded, you can create a snapshot of the VM data structure in the JVM to achieve a similar effect

In short: the snapshot contains a valid representation of all data structures allocated on the dart VM heap required to start executing the script

-Ivan

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>