What is a Smalltalk "image"?
Asked Answered
M

8

30

What is a Smalltalk "image"? Is it like serializing a Smalltalk run-time?

Mazurek answered 24/8, 2010 at 21:22 Comment(0)
T
25

Most popular programming systems separate program code (in the form of class definitions, functions or procedures) from program state (such as objects or other forms of application data). They load the program code when an application is started, and any previous application state has to be recreated explicitly from configuration files or other data sources. Any settings the application programmer doesn't explicitly save, you have to set back up whenever you restart.

Many Smalltalk systems, however, do not differentiate between application data (objects) and code (classes). In fact, classes are objects themselves. Therefore most Smalltalk systems store the entire application state (including both Class and non-Class objects) in an image file. The image can then be loaded by the Smalltalk virtual machine to restore a Smalltalk-like system to a previous state.

http://en.wikipedia.org/wiki/Smalltalk#Image-based_persistence

True answered 24/8, 2010 at 21:28 Comment(1)
Another way to see it is that this is really like the system images you get with OS virtualization software like VirtualBox or VMWare. Except the OS in the image is the Smalltalk system, and it's not organized like a filesystem, but as objects.Borchers
C
24

The Smalltalk image is a very interesting beast. Look at it as a kind of immortality. Many current Smalltalk systems, Pharo, Squeak, VisualWorks among them, share a common ancestor, that is, a Smalltalk image from Xerox PARC. This common ancestor however is not some remote thing, but actually still alive in those modern systems. The modern variants were produced by sending messages to the objects in that image. Some of those messages actually morphed the current objects. Classes are full-blown objects, and creating new classes is done by sending messages to class objects. Some of the objects in a Smalltalk image may date back to 1972, when the first Smalltalk image bootstrapped! Smalltalk images never die, they just fade into something potentially fundamentally different. You should view your application building as not fundamentally different from creating a new Smalltalk version.

Cooperstein answered 1/9, 2010 at 11:3 Comment(0)
D
9

When the smalltalk VM starts, it loads a saved state of objects (yes: including open file streams, windows, threads and more) from the "image" into its memory and resumes execution where it left when the image was saved. At any time during your work, you can "save an image" (aka: a snapshot of the current overall state) into an image file. You can keep multiple images on your disk. Useful if you work on different projects. Images are often (but not in all smalltalk systems) portable across architectures; for example, a squeak image can be loaded into bot a windows and a mac (and even an android) squeak VM. Images are not portable across dialects, and sometimes not across versions within a dialect.

Images usually contain everything - even the debugger, compiler, editors, browsers etc. However, for deployment, it is sometimes useful to "strip" (i.e. remove unused stuff) from an image - either to hide secrets (;-) or to make it smaller (for embedded or mobile devices). Most Smalltalks cannot live without an image, with the exception of Smalltalk/X and (I think) S#-Smalltalk (but I am on thin ice here...)

To save and transport source code, images are not useful - use either fileout in standard format or in xml or in any other transport format (there are many). Images are also not useful for marshalling/unmarshalling; use xml, binarystorage, databases, glorb or any other serialization method for that.

Dicephalous answered 25/8, 2010 at 11:31 Comment(3)
A small precision: file streams are not kept open in the saved image. Some classes can register to do cleanup/reinitialization when the image is saved or reloaded. File descriptors, sockets, the screen bitmap... all point to state that is outside the image, so they would be invalid if the file is removed while the image is stopped, or if the image is moved to a different host. Threads are implemented completely inside the image (like Java's green threads), so they do not map to a system thread, and they can be saved as is, with a debugger etcBorchers
You are right, but actually: Smalltalk/X even tries to reopen a file and reposition it, iff it is a regular file. It is - of course - not done by the VM, but by the classes' optional reinitialize methods (actually: returnFromSnapshot). Also, in st/x, there is no screen bitmap, but instead a number of win32 or x topWindows to recreate. Fair enough, it is actually up to the programmer to add such a returnFromSnapshot method and to decide, what can and how it is to be reconstructed after a so called snapin.Dicephalous
(you are of course also right, that the state is external to the image; however, if you keep a copy of (some of) the state, you can recreate a window, replace the old window-handle, remap and redraw the new window, for example. And that is what is done in the returnFromSnapshot methods).Dicephalous
S
6

It's serialising everything in the whole system, including all development work and all user data. Everything apart from the kernel of the runtime environment.

Smalltalk, like Java, runs on a Virtual Machine running symbolic bytecode, and it contains low-level things like the garbage collector. This makes Smalltalk very portable, and also very write-once-run-anywhere.

Unsurprisingly, this was the inspiration for Java. So the Smalltalk VM (StVM) is the equivalent of the Java Runtime Environment.

In Smalltalk, everything else is stored in RAM. The codebase, which is dynamically compiled on-the-fly for the StVM. All the object data that you've built up by running your vertical and horizontal end-user apps. All the customisation you've done to the windowing environment and its appearance. All the new code you've written. A song you have loaded onto the VM to play in a music player. Any other data, code or objects you're using or have loaded in.

It's all live in the PC's memory.

Periodically, you may want to save the current-state-play to disk. When you do that, you freeze the Smalltalk VM momentarily, and it copies everything into a single disk-file. That disk-file is called the image file, and by default it will have a .image suffix in most distributions on PCs (whether they are running Linux, MacOS, Windows or RiscOS).

It's a like the way you save your work-in-progress when you are in a word-processor or a spreadsheet on a typical PC. Except that this save includes the latest version of the spreadsheet code that the spreadsheet app itself is made out of.

The Smalltalk system does have other ways of securing your data. If you develop any software, or alter any of the codebase that the Smalltalk system is written in, it logs every change to disk in real-time.

You have the option of writing code, or loading an app, that will can save your source-code and it's associated data structures, to distributed source code repositories, or to repositories on your local disc. Or to relational databases. Or to object databases or the newly-fashionable NoSQL databases.

Most pre-written apps backup the data to disk(s) or database(s) on-the-fly.

The image is a save of the entire Smalltalk system, (apart from the Virtual Machine. The Virtual Machine is equivalent to the Java Runtime Environment. Everything else is stored in the image.

Write a new File System to access the underlying OS's discs? That's in the image. (and all the changes have also been logged to disk automatically by the Smalltalk system).

Enter a whole bunch of data into your Smalltalk image-based object database? That's in the image.

Want to do a factory-reset to your Smalltalk system? Simply go back to using the image file you received when you first installed Smalltalk. Want to save the image every hour on the hour, and then restore back to 4 hours ago? Just load the image file from four hours ago.

The image is a copy of everything that the Smalltalk system has in memory. Except for the small, unchanging, vital proportion of the system which is the Virtual Machine.

Synectics answered 7/11, 2015 at 20:31 Comment(0)
T
2

I recommend you read Pharo By Example. To quote from its first chapter,

"The current system image is a snapshot of a running Pharo system, frozen in time. It consists of two files: an .image file, which contains the state of all of the objects in the system (including classes and methods, since they are objects too), and a .changes file, which contains a log of all of the changes to the source code of the system. In Figure 1.1, these files are called pharo.image and pharo.changes."

HTH

Twentyfour answered 25/8, 2010 at 15:46 Comment(0)
S
1

http://book.seaside.st/book/getting-started/pharo-squeak/what-is-image

All Smalltalk objects live in something called an image. An image is a snapshot of memory containing all the objects at a given point in time.

Second hit on google.

Sauder answered 24/8, 2010 at 21:28 Comment(0)
L
1

Put simply, a Smalltalk image is an image of the Smalltalk environment which has been saved at a given point in time. When this image is reloaded into the Smalltalk runtime system, everything is as it was at the time the image was saved.

Images saved by one Smalltalk system cannot, in general, be loaded by a different Smalltalk system.

I find image-based development incredibly empowering. If I get interrupted I can save the image, and when I get back to it I'm right back where I was. Debuggers that were open are still open, waiting to continue. There's very little "got to figure out how to get back where I was" - it's more "OK, let's continue...".

Share and enjoy.

Lachellelaches answered 18/9, 2010 at 0:50 Comment(0)
B
0

In almost every other language (apart from ABAP as far as I have been told by some senior SAP developers), you have a clear separation:

  • Code you are working on which defines logic
  • State of the program you are running
  • database, generally things you need as input for your code

In Smalltalk, all of this can be - note can - in the image. In theory, you can deploy a Smalltalk application in a loaded image which brings all the data and logic and runs the application at startup. In practice, as far as my experience goes, you tend not to do that for reasons.

If you stay inside the image, you have everything available at your disposal, for good or ill. Classes are objects, methods are objects, so you can actually do things like add a

self halt

in a method, run some code which calls this method, change the method while it is being executed, recompile it and have the code continue. You can also do wonderful things like passing method names as string to a method and then performing the argument without having this visible in code anywhere. Both things are very good for learning and trying out. Not so good for production code or maintaining producion code.

The thing I was struggling with in the beginning was that for instance for UI creation, you create a window in the Smalltalk image which is then created "a second time" by the OS, with window handle and everything. Of course, you can save the window with the Smalltalk image, it will also open up again (normally), but what happens internally is that there is a list of windows (i.e. all the UI components) which have been saved with the image in their Smalltalk state. During Image Startup, there is a process that iterates over this list and asks the OS to recreate all of them. In theory, you can do this for everything the OS offers: file handles, resource handles, ports and so on In practice, you probably dont want to do that. The companies I worked at had nice beginner tutorials of code to run before saving your image in order not to get into trouble when restarting the next day.

Ideally, you could combine a Smalltalk image concept with peristence and just store all your objects in a real database. I do not have the overview whether any Smalltalk dialect has done this, however.

Bedding answered 8/4, 2020 at 10:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.