Classes and Metaclasses
Instances of Metaclass, such as OrderedCollection class, Process class, Magnitude class, etc., and instances of instances of Metaclass, such as OrderedCollection, Process, Magnitude, etc., are considered as special objects because each of these objects is unique in the image. That is, there is exactly one instance of Metaclass with the name Dictionary (also known as Dictionary class), and there is only one instance of Dictionary class (also known as Dictionary) in an image.
The uniqueness of these objects can be illustrated by the following example. Suppose there are two objects, A and B, each containing a reference (directly or indirectly) to Dictionary class. After unloading objects A and B and loading them back into the image (call the newly loaded objects 'A' and 'B'), 'A' and 'B' should not be referencing a different Dictionary class than the one already existing in the image; objects 'A' and 'B' should still reference the identical Dictionary class that was in the image before and after A and B were unloaded and reloaded. Thus, these objects make use of dumping and loading replacement (see Combining dumping and loading replacement). They are replaced by an intermediate representation which rebinds to the appropriate object (class or metaclass) in the image where loading is performed.
In order to unload instances of Metaclass and instances of instances of Metaclass as non-special objects (that is, no replacement performed), the ObjectDumper must be explicitly set to handle these instances as ordinary objects. ObjectDumper instance method classesTreatedAsObjects: will override its default setting and unload the specified classes as objects. The following example shows how you can unload the class ObjectSwapper as an object.
Example: Unloading classes as normal objects
| dumper stream|
stream := ReadWriteStream on: ByteArray new.
(dumper := ObjectDumper new)
classesTreatedAsObjects: (Array with: ObjectSwapper);
"So that the CompiledMethods can be dumped as well."
unload: ObjectSwapper intoStream: stream.
classesTreatedAsObjects: nil;
You must be extremely careful when unloading classes as ordinary objects because classes usually contain references to instances of CompiledMethod. You must use ObjectDumper instance method overrideUndumpableClasses or unlink all instance variables that contain references to these instances of CompiledMethod. In the example above, when the object (class ObjectSwapper) is loaded back into an image that already contains the class ObjectSwapper, the newly loaded object, ObjectSwapper, will not be identical to the one already in the image. It is therefore possible for you to create an unstable image which contains more than one instance of Metaclass with the same name. Typical user applications should not use this feature. Advanced applications such as the VA Smalltalk development environment use this feature to implement loading of classes and methods.
Last modified date: 10/16/2017