links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Last updated at 11:34 pm UTC on 23 January 2019


ImageSegment is an object graph swapper and serializer for Squeak Smalltalk developed by D. Ingalls [Ingalls 1997].

In the ImageSegment’s object swapping implementation, there is a list of user defined root objects that are the base of the graph to swap. The graph is then stored in a “segment” which is represented by an instance of the class ImageSegment and contains three sets of objects:

1. root objects: these objects are provided by the user and should be the starting point of object graph,
2. inner objects, and
3. shared objects.

Once the graph is stored in the segment, it can be swapped to disk and the original objects are removed from the Smalltalk system.

(cited from Mariano Martinez PECK, p. 44)



An ImageSegment is a WordArray whose contents are a sequence of heap objects in the VM's native object format. A segment is loaded by invoking a primitive that swizzles the pointers in the word array so that they become valid objects, and then shortening the word array, leaving the objects behind in memory. Since the contents of the WordArray are specific to a given VM architecture one cannot use the primitive loading mechanism to load segments from VMs with different object representations. Here different means

But there is no reason why Smalltalk code could not parse the contents of the WordArray and hence load objects by creating them based on the data in the WordArray. This would allow image segments to be loaded in any format the Smalltalk code supported (and it would be interesting to compare performance and see how much slower "synthesized" loading would be). This would provide legacy support for segments from "old" versions (Note: As of June 2018, Squeak 5.2 this is supported to a considerable extent by LegacyImageSegment, the 6502 format and 6521 formats are supported), and maybe even provide a oath to adopting a more neutral format such as Fuel.

To implement such a system one would have to understand the object formats of each system, using the VM source code as a guide, both the object representation and the load and save primitives themselves.



ImageSegments are a very fast binary object storage mechanism.
From the class comment - 3.3a-4769)
I represent a segment of Squeak address space. I am created from an array of root objects. After storing, my segment contains a binary encoding of every object accessible from my roots but not otherwise accessible from anywhere else in the system. My segment contains outward pointers that are indices into my table of outPointers.
When a segment is written out onto a file, it goes in a folder called image name_segs.
If your image is called "Squeak2.6.image", the folder "Squeak2.6_segs" must accompany the image whenever your move, copy, or rename it.
Whenever a Class is in arrayOfRoots, its class (aClass class) must also be in the arrayOfRoots.

See also Introduction to ImageSegments

There are two kinds of image segments.

Mariano Martinez Peck 1, Noury Bouraqadi, Stéphane Ducasse, Luc Fabresse

Inria open archive
Object Swapping Challenges - an Evaluation of ImageSegment

ACM digital library
Object swapping challenges: An evaluation of imageSegment

Eliot Miranda Thu, Sep 22, 2016 at 9:07 PM
Reply-To: Squeak Virtual Machine Development Discussion
To: The general-purpose Squeak developers list
Cc: Squeak Virtual Machine Development Discussion , Pharo Development List

Hi Ron, Hi All,

On Thu, Sep 22, 2016 at 11:58 AM, Ron Teitelbaum wrote:

Hi All,

We are using ImageSegment for transferring croquet island state. Is this something covered in the changes from Bert or are we talking about dropping ImageSegment altogether?

I suppose I should explain. At ESUG Bert and others announced support for Toys in Squeak 5.1. As part of this work, ImageSegment loading and saving was moved from the VM up into pure Smalltalk code. This allows Squeak 5.1 (Spur) to load image segments saved on pre-Spur VMs. Consequent;ly we no longer need VM support for ImageSegment. Instead we can use the pure image-level code Bert has kindly written. The question is then at what point can we nuke the Spur VM support, since it is now superfluous.

Bert, am I jumping the gun? Do we still need to write image-level support for writing image segments? If this is the case, Igor Stasenko described a primitive for collecting the set of objects to be written out. It is the initial part of the segment-writing primitive that collects the transitive closure of objects reachable only from those root objects.

Max Leske Mon, Sep 26, 2016 at 9:43 PM
Reply-To: The general-purpose Squeak developers list
To: The general-purpose Squeak developers list

Hi Bert,

No, we use ImageSegment directly (we’ve subclassed ImageSegment). Here’s the short version:

1. we copy the roots:

 	copyFromRoots: (Array with: anObject)
 	sizeHint: self fileSize // 2
 	areUnique: true.

2. we write the segment onto a MutliByteFileStream (which we’ve subclassed):

 	forceNewFileNamed: fileName
 	do: [ :stream | stream writeObject: self ].

where #writeObject: is implemented as:

 writeObject: anObject
 	(SmartRefStream on: self) nextPutObjOnly: anObject

We load the segment back by:

1. opening a MultiByteFileStream and sending the installation message:

 	readOnlyFileNamed: (aDirectory fullNameFor: filename)
 	do: [ :stream |
 	installSegmentFrom: stream
 	andDo: aBlock ]

2. #installSegmentFrom:andDo: basically sends #readObject to the file stream:

 	"This is a hack to allow for the old segments (mixed code and objects)
 	to be loaded without the #inform: in #nextAndClose opening a UI element."
 	^ self binary peek = ReferenceStream versionCode
 	ifTrue: [ (SmartRefStream on: self) nextAndClose ]
 	ifFalse: [
 	| object |
 	object := SmartRefStream scannedObject.
 	SmartRefStream scannedObject: nil.
 	object ]

3. and once we have the segment we send #install to it

We’ve made some modifications here and there (e.g. to suppress UI elements) but the above is the gist of it. I can give you the full source if you need it.
It’s possible that this is all overkill or parallels functionality found in other places. I’ve inherited the code and haven’t spent the time exploring improvements in that area.


Eliot Miranda Mon, Oct 20, 2014 at 9:41 PM
Reply-To: Squeak Virtual Machine Development Discussion
To: Pharo Development List
Cc: Squeak Virtual Machine Development Discussion , The general-purpose Squeak developers list

On Mon, Oct 20, 2014 at 8:26 AM, stepharo wrote:

While I as a big fan of imageSegment and proposed to Mariano to work on imageSegment2 (it was the original idea for his phd)
he convinced us that imagesegment were not worth their complexity.

I absolutely agree.

So why do you want to have imageSegment?

Because of backwards-compatibility. If Spur does not provide image segments then the barrier to entry for Terf, eToys and Squeak may be too high. Spur is supposed to be a plug-in replacement for Cog, not something that requires lots of effort to port to.


stepharo Mon, Oct 20, 2014 at 9:55 PM
Reply-To: Pharo Development List
To: Pharo Development List

Sorry for breaking the stream. I could not find the email with thunderbird :(

Just for the record, you see what netstyle people did: they use image segment and they had to kill everything (like processes and others) because of
possible pointers so after saving a segment the image was basically dead because some escaping pointers to make a kind of memory leak.
Now they migrated to Fuel.

So now I think that people should better use Fuel. IS were nice at first but not when you look carefully to them, especially when you have
an object not in the roots pointing to an object inside the graph. Then you have to do a GC…. Mariano spent a year fighting with that
and his PhD is really nice.

Less magic, more stability, simpler VMs.

Because all the energy that you will put in something from the past will not be put in things for the future(not counting the bug hunting).

See also

Fuel serialization approach, BOSS (Binary Object Storage System), Parcels and ImageSegments