21

In smalltalk, you're able to save the state of the world into an image file. I assume this has to do with Smalltalk's ability to "serialize" itself -- that is, objects can produce their own source code.

1) Is this an accurate understanding?

2) What is the challenge in adding this ability to modern languages (non-lisp, obviously)?

3) Is "serialization" the right word? What's the correct jargon?

4 Answers 4

18

It's much simpler than "serializing". A Smalltalk image is simply a snapshot of the object memory. It takes the whole RAM contents (after garbage collecting) and dumps it into a file. On startup, it loads that snapshot from disk into RAM and continues processing where it left off. 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)

2
  • Note that this works well because smalltalk runs in its own VM, so it organises its own memory state, and manages it itself. If you tried to do this with a C program not built for this, it would probably be fine most of the time, but corner-cases might creep up.
    – Marcin
    Commented Nov 16, 2012 at 21:37
  • 9
    What helps the snapshotting is that the execution state (e.g. processes, stack frames) is part of the normal object memory. This makes it particularly simple to snapshot and resume running code. Commented Nov 17, 2012 at 11:13
9

Extending upon Bert Freudenberg’s excellent answer.

1) Is this (ie object's ability to serialize their own source code) an accurate understanding?

Nope. As Bert pointed out a Smalltalk image is simply a memory snapshot. The single-source-of-truth of both Smalltalk objects and Smalltalk programs is their memory representation. 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)?

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. 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. And also, there's a startup hook to fix the endianness of numbers.

3) Is "serialization" the right word? What's the correct jargon?

Hibernation is the term.

2
  • Where can I read about how the Smalltalk VM is able to reopen files and network connections? And what the in-memory represention is? I don't see any easily readable Smalltalk sources anywhere...thank you very much.
    – dave paola
    Commented Feb 27, 2013 at 23:39
  • Download the Pharo one-click image from pharo-project.org and browse the sources. I don't recall the relevant messages of the top of my head, but they should be found in the file and connection classes.
    – akuhn
    Commented Feb 28, 2013 at 6:48
2

Crucial difference is that Smalltalk treats Program just as bunch of objects. 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.

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.

1

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? 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.

2
  • "just a matter of implementing the feature in the Python/Ruby interpreter and stdlib" You mean, just a matter of creating your own implementation? Why, that won't take long at all ;)
    – Marcin
    Commented Nov 16, 2012 at 21:39
  • 1
    Yea, your own implementation of the hibernation feature. You don't have to write the whole interpreter.. Not that I am volunteering. Commented Nov 17, 2012 at 23:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.