简体   繁体   English

是什么让Smalltalk能够进行图像持久化,为什么像Ruby / Python这样的语言不能自行序列化?

[英]What gives Smalltalk the ability to do image persistence, and why can't languages like Ruby/Python serialize themselves?

In smalltalk, you're able to save the state of the world into an image file. 在smalltalk中,您可以将世界状态保存到图像文件中。 I assume this has to do with Smalltalk's ability to "serialize" itself -- that is, objects can produce their own source code. 我认为这与Smalltalk自身“序列化”的能力有关 - 也就是说,对象可以生成自己的源代码。

1) Is this an accurate understanding? 1)这是一个准确的理解吗?

2) What is the challenge in adding this ability to modern languages (non-lisp, obviously)? 2)将这种能力添加到现代语言中的挑战是什么(非lisp,显然)?

3) Is "serialization" the right word? 3)“序列化”是正确的词吗? What's the correct jargon? 什么是正确的行话?

It's much simpler than "serializing". 它比“序列化”简单得多。 A Smalltalk image is simply a snapshot of the object memory. Smalltalk图像只是对象内存的快照。 It takes the whole RAM contents (after garbage collecting) and dumps it into a file. 它占用整个RAM内容(在垃圾收集之后)并将其转储到文件中。 On startup, it loads that snapshot from disk into RAM and continues processing where it left off. 在启动时,它将该快照从磁盘加载到RAM中并继续处理它停止的位置。 There are some hooks to perform special actions on snapshot and when resuming, but basically this is how it works. 有一些钩子可以对快照和恢复时执行特殊操作,但基本上这就是它的工作原理。

(added: see Lukas Renggli's comment below for a crucial design choice that makes it so simple compared to other environments) (补充说:请参阅下面的Lukas Renggli的评论,其中一个关键的设计选择使其与其他环境相比如此简单)

Extending upon Bert Freudenberg's excellent answer. 扩展Bert Freudenberg的优秀答案。

1) Is this (ie object's ability to serialize their own source code) an accurate understanding? 1)这是否(即对象能够序列化自己的源代码)是否准确理解?

Nope. 不。 As Bert pointed out a Smalltalk image is simply a memory snapshot. 正如Bert所指出的,Smalltalk图像只是一个内存快照。 The single-source-of-truth of both Smalltalk objects and Smalltalk programs is their memory representation. Smalltalk对象和Smalltalk程序的单一事实来源是它们的内存表示。 This is a huge difference to other languages, where programs are represented as text files. 这与其他语言存在巨大差异,其中程序表示为文本文件。

2) What is the challenge in adding this ability to modern languages (non-lisp, obviously)? 2)将这种能力添加到现代语言中的挑战是什么(非lisp,显然)?

Technically, bootstrapping an application from a memory snapshot should be possible for most languages. 从技术上讲,对于大多数语言来说,应该可以从内存快照引导应用程序。 If I am not mistaken there are solutions that use this approach to speedup startup times for Java applications. 如果我没有弄错,有些解决方案使用这种方法来加速Java应用程序的启动时间。 You'd have to agree on a canonical memory representation though and you'd need to make care to reinitialize native resources upon restarting the program. 您必须同意规范内存表示,并且您需要注意在重新启动程序时重新初始化本机资源。 For example, in Smalltalk, open files and network connecting are reopened. 例如,在Smalltalk中,重新打开打开的文件和网络连接。 And also, there's a startup hook to fix the endianness of numbers. 而且,还有一个启动挂钩来修复数字的字节序。

3) Is "serialization" the right word? 3)“序列化”是正确的词吗? What's the correct jargon? 什么是正确的行话?

Hibernation is the term. 休眠就是这个词。

This happens already in a way when you put your computer to sleep, right? 当你把电脑睡觉时,这种情况已经发生了,对吧? The kernel writes running programs to disk and loads them up again later? 内核将正在运行的程序写入磁盘并在以后再次加载它们? Presumably the kernel could move a running program to a new machine over a network, assuming same architecture on the other end? 据推测,内核可以通过网络将正在运行的程序移动到新机器上,假设另一端有相同的架构? Java can serialized all objects also because of the JVM, right? 由于JVM,Java也可以序列化所有对象,对吧? Maybe the hurdle is just architecture implying varied memory layouts? 也许障碍只是建筑意味着不同的内存布局?

Edit: But I guess you're interested in using this functionality from the program itself. 编辑:但我想你有兴趣从程序本身使用这个功能。 So I think it's just a matter of implementing the feature in the Python/Ruby interpreter and stdlib, and having some kind of virtual machine if you want to be able to move to a different hardware architecture. 所以我认为这只是在Python / Ruby解释器和stdlib中实现该功能的问题,并且如果您希望能够移动到不同的硬件架构,则需要某种虚拟机。

Crucial difference is that Smalltalk treats Program just as bunch of objects. 最重要的区别是Smalltalk将程序视为一堆对象。 And IDE is just a bunch of editors editing those objects, so when you save-load image, all your code is there just as when you left off. IDE只是编辑这些对象的一堆编辑器,因此当您保存加载图像时,所有代码就像您离开时一样。

For other languages it could be possible to do so, but I guess there would be more fiddling, depending on how much reflection there is. 对于其他语言,它可以这样做,但我想会有更多的摆弄,取决于有多少反射。 In most other languages, reflection comes as add-on, or even afterthought, but in Smalltalk it is in the heart of the system. 在大多数其他语言中,反射是附加的,甚至是后来的,但在Smalltalk中,它是系统的核心。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM