when reloading modules, let the old (in-image) class #become the new class
authorClaus Gittinger <cg@exept.de>
Wed, 05 Jun 1996 20:05:46 +0200
changeset 286 2413836651f8
parent 285 19e8d6d22278
child 287 dc42dd240e5c
when reloading modules, let the old (in-image) class #become the new class
ObjFLoader.st
ObjectFileLoader.st
--- a/ObjFLoader.st	Wed May 29 17:41:46 1996 +0200
+++ b/ObjFLoader.st	Wed Jun 05 20:05:46 1996 +0200
@@ -1002,7 +1002,8 @@
     "reload all object modules as were loaded when the image was saved.
      Some care has to be taken, if files are missing or otherwise corrupted."
 
-    |oldDummyMethod where m newHandle savedByteCodeMethods savedMethods|
+    |oldDummyMethod where m newHandle 
+     savedOldClasses savedByteCodeMethods savedMethods|
 
     PreviouslyLoadedObjects notNil ifTrue:[
         PreviouslyLoadedObjects do:[:entry |
@@ -1014,10 +1015,16 @@
 
             handle isClassLibHandle ifTrue:[
                 ('OBJFLOADER: reloading classes in ' , fileName , ' ...') infoPrintNL.
+
+                "/
+                "/ remember all byteCode methods (as added in the session)
+                "/                
                 savedByteCodeMethods := IdentityDictionary new.
+                savedOldClasses := IdentitySet new.
 
                 handle classes do:[:aClass |
                     savedMethods := IdentityDictionary new.
+                    savedOldClasses add:aClass.
                     aClass methodDictionary keysAndValuesDo:[:sel :m |
                         m byteCode notNil ifTrue:[
                             "/ an interpreted method - must be preserved
@@ -1028,18 +1035,54 @@
                         savedByteCodeMethods at:(aClass name) put:savedMethods
                     ].
                 ].
+                "/
+                "/ load the class binary
+                "/                
                 self loadObjectFile:fileName.
 
+                "/
+                "/ reinstall the byteCode methods
+                "/                
                 savedByteCodeMethods keysAndValuesDo:[:nm :savedMethods |
                     |cls|
 
                     cls := Smalltalk classNamed:nm.
                     savedMethods keysAndValuesDo:[:sel :m |
-"/ ('preserving ' , cls name , '>>' , sel) printNL.
-                        cls primAddSelector:sel withMethod:m 
+                        cls primAddSelector:sel withMethod:m. 
+"/ ('preserved ' , cls name , '>>' , sel) printNL.
+                    ]
+                ].
+
+                "/
+                "/ validate old-classes vs. new classes.
+                "/ and if things look ok, get rid of old stuff
+                "/ and make instances become instances of the new class
+                "/
+                savedOldClasses do:[:oldClass |
+                    |newClass|
+
+                    newClass := Smalltalk classNamed:(oldClass name).
+                    (newClass isNil or:[newClass == oldClass]) ifTrue:[
+                        ('OBJFLOADER: reload of ' , oldClass name , ' seemed to fail.') errorPrintCR.
+                    ] ifFalse:[
+"/'oldSize: ' print. oldClass instSize print. ' (' print. oldClass instSize class name print. ') ' print.
+"/'newSize: ' print. newClass instSize print. ' (' print. oldClass instSize class name print. ') ' printCR.
+
+                        oldClass instSize ~~ newClass instSize ifTrue:[
+                            ('OBJFLOADER: ' , oldClass name , ' has changed its size.') errorPrintCR.
+                        ] ifFalse:[
+                            oldClass class instSize ~~ newClass class instSize ifTrue:[
+                                ('OBJFLOADER: ' , oldClass name , ' class has changed its size.') errorPrintCR.
+                            ] ifFalse:[
+                                ('OBJFLOADER: migrating ' , oldClass name) errorPrintCR.
+                                oldClass becomeSameAs:newClass
+                            ]
+                        ]
                     ]
                 ]
+
             ] ifFalse:[
+
                 handle isMethodHandle ifTrue:[
                     oldDummyMethod := handle method.
                     (oldDummyMethod isKindOf:Method) ifFalse:[
@@ -1073,7 +1116,7 @@
         PreviouslyLoadedObjects := nil
     ]
 
-    "Modified: 18.3.1996 / 14:51:54 / cg"
+    "Modified: 5.6.1996 / 20:05:03 / cg"
 !
 
 rememberAllObjectFiles
@@ -3211,6 +3254,6 @@
 !ObjectFileLoader class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/Attic/ObjFLoader.st,v 1.96 1996-05-28 18:20:22 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/Attic/ObjFLoader.st,v 1.97 1996-06-05 18:05:46 cg Exp $'
 ! !
 ObjectFileLoader initialize!
--- a/ObjectFileLoader.st	Wed May 29 17:41:46 1996 +0200
+++ b/ObjectFileLoader.st	Wed Jun 05 20:05:46 1996 +0200
@@ -1002,7 +1002,8 @@
     "reload all object modules as were loaded when the image was saved.
      Some care has to be taken, if files are missing or otherwise corrupted."
 
-    |oldDummyMethod where m newHandle savedByteCodeMethods savedMethods|
+    |oldDummyMethod where m newHandle 
+     savedOldClasses savedByteCodeMethods savedMethods|
 
     PreviouslyLoadedObjects notNil ifTrue:[
         PreviouslyLoadedObjects do:[:entry |
@@ -1014,10 +1015,16 @@
 
             handle isClassLibHandle ifTrue:[
                 ('OBJFLOADER: reloading classes in ' , fileName , ' ...') infoPrintNL.
+
+                "/
+                "/ remember all byteCode methods (as added in the session)
+                "/                
                 savedByteCodeMethods := IdentityDictionary new.
+                savedOldClasses := IdentitySet new.
 
                 handle classes do:[:aClass |
                     savedMethods := IdentityDictionary new.
+                    savedOldClasses add:aClass.
                     aClass methodDictionary keysAndValuesDo:[:sel :m |
                         m byteCode notNil ifTrue:[
                             "/ an interpreted method - must be preserved
@@ -1028,18 +1035,54 @@
                         savedByteCodeMethods at:(aClass name) put:savedMethods
                     ].
                 ].
+                "/
+                "/ load the class binary
+                "/                
                 self loadObjectFile:fileName.
 
+                "/
+                "/ reinstall the byteCode methods
+                "/                
                 savedByteCodeMethods keysAndValuesDo:[:nm :savedMethods |
                     |cls|
 
                     cls := Smalltalk classNamed:nm.
                     savedMethods keysAndValuesDo:[:sel :m |
-"/ ('preserving ' , cls name , '>>' , sel) printNL.
-                        cls primAddSelector:sel withMethod:m 
+                        cls primAddSelector:sel withMethod:m. 
+"/ ('preserved ' , cls name , '>>' , sel) printNL.
+                    ]
+                ].
+
+                "/
+                "/ validate old-classes vs. new classes.
+                "/ and if things look ok, get rid of old stuff
+                "/ and make instances become instances of the new class
+                "/
+                savedOldClasses do:[:oldClass |
+                    |newClass|
+
+                    newClass := Smalltalk classNamed:(oldClass name).
+                    (newClass isNil or:[newClass == oldClass]) ifTrue:[
+                        ('OBJFLOADER: reload of ' , oldClass name , ' seemed to fail.') errorPrintCR.
+                    ] ifFalse:[
+"/'oldSize: ' print. oldClass instSize print. ' (' print. oldClass instSize class name print. ') ' print.
+"/'newSize: ' print. newClass instSize print. ' (' print. oldClass instSize class name print. ') ' printCR.
+
+                        oldClass instSize ~~ newClass instSize ifTrue:[
+                            ('OBJFLOADER: ' , oldClass name , ' has changed its size.') errorPrintCR.
+                        ] ifFalse:[
+                            oldClass class instSize ~~ newClass class instSize ifTrue:[
+                                ('OBJFLOADER: ' , oldClass name , ' class has changed its size.') errorPrintCR.
+                            ] ifFalse:[
+                                ('OBJFLOADER: migrating ' , oldClass name) errorPrintCR.
+                                oldClass becomeSameAs:newClass
+                            ]
+                        ]
                     ]
                 ]
+
             ] ifFalse:[
+
                 handle isMethodHandle ifTrue:[
                     oldDummyMethod := handle method.
                     (oldDummyMethod isKindOf:Method) ifFalse:[
@@ -1073,7 +1116,7 @@
         PreviouslyLoadedObjects := nil
     ]
 
-    "Modified: 18.3.1996 / 14:51:54 / cg"
+    "Modified: 5.6.1996 / 20:05:03 / cg"
 !
 
 rememberAllObjectFiles
@@ -3211,6 +3254,6 @@
 !ObjectFileLoader class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/ObjectFileLoader.st,v 1.96 1996-05-28 18:20:22 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/ObjectFileLoader.st,v 1.97 1996-06-05 18:05:46 cg Exp $'
 ! !
 ObjectFileLoader initialize!