Archive for 1337

the smallest object memory so far

Posted in Appsterdam, consulting, Smalltalk, Spoon with tags , , , , , on 21 October 2012 by Craig Latta

The smallest object memory snapshot I’ve made so far is 1,337 bytes long, on 19 January 2006. You can get the bits (also see my notes about the visualization tools). It adds 3 and 4, then quits.

I created it with a new version of the Squeak system tracer that I wrote. This tracer is implemented as a feature of the Squeak virtual machine simulator. It keeps track of all the objects that are touched during a particular duration of operation, then uses that information to guide a final garbage collection and snapshot.

When you run the snapshot, the virtual machine gets the object address (“oop”) for the special-objects array from the snapshot header. Note that the snapshot header doesn’t appear in this picture. The visualization is of the object memory bytes after they’ve been read from the snapshot file, not the snapshot file itself. The header is the only use of bytes in the snapshot file other than the object memory bytes.

Indirectly from the special-objects array (through the Processor and its active process) the virtual machine finds the active context and continues execution. The instructions executed come from a method used by the context. The instructions are: push (3), push (4), add, send (#quitPrimitive). The send invokes >>quitPrimitive, another method. That method terminates the virtual machine via a primitive. The virtual machine needs to look up >>quitPrimitive in the method dictionary of the class of Smalltalk, a literal association in the literal frame of the initial context.

In the above, we’ve touched the following objects from the snapshot file, in the following order:

  1. the special-objects array
  2. the global Processor association
  3. the Processor
  4. the active Process
  5. the active Process’s suspended context
  6. the now-active context’s method
  7. the symbol #quitPrimitive from the context’s literal frame
  8. the global Smalltalk association
  9. the system dictionary (Smalltalk)
  10. class SystemDictionary
  11. SystemDictionary’s method dictionary
  12. SystemDictionary’s method dictionary’s association array
  13. nil (touched during method lookup)
  14. that array’s association for key #quitPrimitive
  15. the value for key #quitPrimitive (the second method)

The method dictionary of the first method is in there also, as is true and false, making 18 objects. (The numbers 3 and 4 are immediates in the first method’s literal frame.) I could kill those last three, but I declared victory when I got the thing under 1,337 bytes. :)

%d bloggers like this: