Advanced features
This section describes some advanced features of the Swapper. For information on the methods mentioned, examine the comments for the methods in a Smalltalk browser.
Extracting instances from a loaded object
In most cases, an unloaded object consists of an aggregate of complex heterogeneous objects. When the object is loaded into the image it requires a considerable amount of work to extract all instances of a certain class from the newly loaded object. The methods extractInstancesOfClasses: and requestedNewlyLoadedInstances in the class ObjectLoader allow you to perform the task described above with minimal cost of time and effort.
Error object
When an error occurs during an object dump or load, the Swapper allows you to access the object which relates to or causes the error. For example, the default behavior of an ObjectDumper disallows instances of CompiledMethod to be unloaded. If an instance of CompiledMethod is encountered by the ObjectDumper, an error will be returned, and the error object will be the instance of CompiledMethod encountered. The method errorObject in the class ObjectSwapper allows you to access the object.
Warnings
There are cases where the Swapper will generate a warning instead of an error. Since warnings are not fatal to the operation of the Swapper, it will continue its current operation until it either successfully completes its task or encounters an error. All warning codes and the corresponding objects which cause the warnings to occur will be stored in two separate ordered collections. You can query these collections to determine the status of the Swapper and its most recent task. Each warning code can be interpreted into a descriptive warning string. Error or warning messages can be returned by sending the message messageStringFor: in ObjectSwapper. A list of error and warning codes can be found in Error codes and their expected error objects. The methods warnings and warnedObjects in ObjectSwapper are used for warning information.
Include instance variable names
The Swapper includes the class definition of each class (class name and instance variable names) whose instances are unloaded from or loaded into the image. The default behavior of an ObjectDumper is to include the instance variable names in the unloading process, and the default behavior of an ObjectLoader is to use the instance variable names to verify that the class definitions of the unloaded objects match the ones in the image.
The main purpose of including the instance variable names is to let the Swapper support object mutation. The size of an average object dump will increase by approximately five to ten percent when including the instance variable names. Applications which are concerned about dumping space can configure the Swapper to exclude instance variable names in the unloading process, and ignore the instance variable names in the loading process.
The methods includeInstVarNames and includeInstVarNames: in ObjectSwapper are used to include instance variables.
Object mutation
All unloaded objects contain a reference to their class definitions. When objects are loaded into an image these definitions are compared with the definitions currently in the image. If there is a difference between the definitions, the loaded objects will be mutated to conform with the definitions in the image. You can specify your own mutation code by overriding the default method provided by the Swapper (mutateObjects:fromPlatform:named:withDefinition: in Behavior), or specify the mapping of the class names of unloaded objects with the new classes currently in the image.
The mutation process relies on the fact that the Swapper is set up to include the instance variable names of each class whose instances are unloaded and loaded.
The methods addMutatedClassNamed:newClass: and removeMutatedClassNamed: in ObjectLoader and the methods mutateObjects:fromPlatform:named:withDefinition: and defaultInstanceVariableMappings in Behavior handle object mutation.
Objects output buffer limit
This feature allows you to specify a buffer limit in order to minimize garbage collection when the objects are reloaded. The default value of this buffer limit is 128K. The methods outputBufferLimit and outputBufferLimit: in ObjectDumper are used to specify buffer limits.
Last modified date: 05/19/2020