SnapShotImageMemory.st
changeset 1417 28d6026fe30c
parent 1416 eec0911414fe
child 1419 f808d17ff6f5
equal deleted inserted replaced
1416:eec0911414fe 1417:28d6026fe30c
       
     1 'From Smalltalk/X, Version:4.1.1 on 24-Okt-2000 at 12:50:47'                    !
       
     2 
     1 "{ Package: 'cg:private' }"
     3 "{ Package: 'cg:private' }"
     2 
     4 
     3 Object subclass:#SnapShotImageMemory
     5 Object subclass:#SnapShotImageMemory
     4 	instanceVariableNames:'stream msb ptrSize intSize intTag spaceInfos symbolEntries
     6 	instanceVariableNames:'image stream msb ptrSize intSize intTag spaceInfos symbolEntries
     5 		globalEntries addrToObjectMapping'
     7 		globalEntries addrToObjectMapping'
     6 	classVariableNames:''
     8 	classVariableNames:''
     7 	poolDictionaries:''
     9 	poolDictionaries:''
     8 	category:'System-Support'
    10 	category:'System-Support'
       
    11 !
       
    12 
       
    13 Object subclass:#ImageHeader
       
    14 	instanceVariableNames:'memory classRef bits byteSize'
       
    15 	classVariableNames:''
       
    16 	poolDictionaries:''
       
    17 	privateIn:SnapShotImageMemory
     9 !
    18 !
    10 
    19 
    11 Object subclass:#SpaceInfo
    20 Object subclass:#SpaceInfo
    12 	instanceVariableNames:'start end size flags imageBase'
    21 	instanceVariableNames:'start end size flags imageBase'
    13 	classVariableNames:''
    22 	classVariableNames:''
    14 	poolDictionaries:''
    23 	poolDictionaries:''
    15 	privateIn:SnapShotImageMemory
    24 	privateIn:SnapShotImageMemory
    16 !
    25 !
    17 
    26 
    18 Object variableSubclass:#ImageObject
    27 SnapShotImageMemory::ImageHeader variableSubclass:#ImageObject
    19 	instanceVariableNames:'classRef size bits'
    28 	instanceVariableNames:''
    20 	classVariableNames:''
    29 	classVariableNames:''
    21 	poolDictionaries:''
    30 	poolDictionaries:''
    22 	privateIn:SnapShotImageMemory
    31 	privateIn:SnapShotImageMemory
    23 !
    32 !
    24 
    33 
    27 	classVariableNames:''
    36 	classVariableNames:''
    28 	poolDictionaries:''
    37 	poolDictionaries:''
    29 	privateIn:SnapShotImageMemory
    38 	privateIn:SnapShotImageMemory
    30 !
    39 !
    31 
    40 
       
    41 SnapShotImageMemory::ImageHeader variableByteSubclass:#ImageByteObject
       
    42 	instanceVariableNames:''
       
    43 	classVariableNames:''
       
    44 	poolDictionaries:''
       
    45 	privateIn:SnapShotImageMemory
       
    46 !
       
    47 
    32 
    48 
    33 !SnapShotImageMemory class methodsFor:'instance creation'!
    49 !SnapShotImageMemory class methodsFor:'instance creation'!
    34 
    50 
    35 for:aFilename
    51 for:aFilename
    36     ^ self new for:aFilename
    52     ^ self new for:aFilename
    58     ^ globalEntries!
    74     ^ globalEntries!
    59 
    75 
    60 globalEntries:something
    76 globalEntries:something
    61     "set the value of the instance variable 'globalEntries' (automatically generated)"
    77     "set the value of the instance variable 'globalEntries' (automatically generated)"
    62 
    78 
    63     globalEntries := something.! !
    79     globalEntries := something.!
       
    80 
       
    81 image
       
    82 
       
    83     ^ image
       
    84 !
       
    85 
       
    86 image:something
       
    87 
       
    88     image := something.
       
    89 !
       
    90 
       
    91 ptrSize
       
    92     "return the value of the instance variable 'ptrSize' (automatically generated)"
       
    93 
       
    94     ^ ptrSize!
       
    95 
       
    96 ptrSize:something
       
    97     "set the value of the instance variable 'ptrSize' (automatically generated)"
       
    98 
       
    99     ptrSize := something.! !
    64 
   100 
    65 !SnapShotImageMemory methodsFor:'object access'!
   101 !SnapShotImageMemory methodsFor:'object access'!
    66 
   102 
       
   103 fetchByteAt:addr
       
   104     |byte imgAddr|
       
   105 
       
   106     imgAddr := self imageAddressOf:addr.
       
   107     stream position:imgAddr.
       
   108     byte := stream next.
       
   109     ^ byte
       
   110 !
       
   111 
    67 fetchClassObjectAt:baseAddr
   112 fetchClassObjectAt:baseAddr
    68     |addr classPtr size bits o|
   113     |addr classPtr size bits o classRef nInsts|
       
   114 
       
   115     (baseAddr bitAnd:3) ~~ 0 ifTrue:[self halt].
    69 
   116 
    70     o := addrToObjectMapping at:baseAddr ifAbsent:nil.
   117     o := addrToObjectMapping at:baseAddr ifAbsent:nil.
    71     o notNil ifTrue:[^ o].
   118     o notNil ifTrue:[^ o].
    72 
   119 
    73     addr := baseAddr.
   120     addr := baseAddr.
    76     size := self fetchUnboxedIntegerAt:addr.
   123     size := self fetchUnboxedIntegerAt:addr.
    77     addr := addr + ptrSize.
   124     addr := addr + ptrSize.
    78     bits := self fetchUnboxedIntegerAt:addr.
   125     bits := self fetchUnboxedIntegerAt:addr.
    79     addr := addr + ptrSize.
   126     addr := addr + ptrSize.
    80 
   127 
    81     o := ImageClassObject new:(size - intSize - intSize - intSize).
   128     nInsts := (size - (intSize *3)) // intSize.
    82     o classRef:classPtr.
   129     o := ImageClassObject new:nInsts.
    83     o size:size.
   130     addrToObjectMapping at:baseAddr put:o.
       
   131 
       
   132     (self class isPointerOOP:classPtr) ifFalse:[
       
   133         self halt
       
   134     ].
       
   135 
       
   136     classRef := self fetchClassObjectAt:classPtr.
       
   137 
       
   138     o classRef:classRef.
       
   139 size > 8000 ifTrue:[self halt].
       
   140     o byteSize:size.
    84     o bits:bits.
   141     o bits:bits.
    85 
   142 
    86     1 to:size // intSize do:[:idx |
   143     1 to:nInsts do:[:idx |
    87         o at:idx put:(self fetchUnboxedIntegerAt:addr).
   144         o at:idx put:(self fetchUnboxedIntegerAt:addr).
    88         addr := addr + 1.
   145 "/        o at:idx put:(self fetchObjectAt:(self fetchUnboxedIntegerAt:addr)).
    89     ].
   146         addr := addr + ptrSize.
    90 
   147     ].
    91     addrToObjectMapping at:baseAddr put:o.
   148     o memory:self.
    92     ^ o
   149     ^ o
    93 !
   150 !
    94 
   151 
    95 fetchObjectAt:baseAddr
   152 fetchObjectAt:baseAddr
    96     |addr classPtr classRef size bits o|
   153     |addr classPtr classRef size bits o nBytes nInsts flags imgAddr|
       
   154 
       
   155     baseAddr == 0 ifTrue:[^ nil].
       
   156     (baseAddr bitAnd:1) == 1 ifTrue:[(baseAddr bitTest:16r80000000) ifTrue:[
       
   157                                          ^ (baseAddr - 16r100000000) bitShift32:-1
       
   158                                      ] ifFalse:[   
       
   159                                          ^ baseAddr bitShift32:-1
       
   160                                      ]
       
   161                                     ].
       
   162     (baseAddr bitAnd:3) ~~ 0 ifTrue:[self halt].
    97 
   163 
    98     o := addrToObjectMapping at:baseAddr ifAbsent:nil.
   164     o := addrToObjectMapping at:baseAddr ifAbsent:nil.
    99     o notNil ifTrue:[^ o].
   165     o notNil ifTrue:[^ o].
   100 
   166 
   101     addr := baseAddr.
   167     addr := baseAddr.
   109     (self class isPointerOOP:classPtr) ifFalse:[
   175     (self class isPointerOOP:classPtr) ifFalse:[
   110         self halt
   176         self halt
   111     ].
   177     ].
   112 
   178 
   113     classRef := self fetchClassObjectAt:classPtr.
   179     classRef := self fetchClassObjectAt:classPtr.
   114     classRef isImageBehavior ifFalse:[
   180 
   115         self halt.
   181     flags := classRef flags bitAnd:Behavior maskIndexType.
   116     ].
   182     (flags = Behavior flagBytes) ifTrue:[ 
   117 
   183         nBytes := (size - (intSize * 3)).
   118     o := ImageObject new:(size - intSize - intSize - intSize).
   184         o := ImageByteObject new:nBytes.
   119     o classRef:classRef.
   185         o classRef:classRef.
   120     o size:size.
   186 size > 8000 ifTrue:[self halt].
   121     o bits:bits.
   187         o byteSize:size.
   122 
   188         o bits:bits.
   123     self halt.
   189 
   124 !
   190         imgAddr := self imageAddressOf:addr.
   125 
   191         stream position:imgAddr.
   126 fetchObjectHeaderAt:baseAddr
   192 
   127     |addr class size bits|
   193         1 to:nBytes do:[:idx |
   128 
   194             o at:idx put:(stream next).
   129     addr := baseAddr.
   195             addr := addr + 1.
   130     class := self fetchPointerAt:addr.
   196         ].
   131     addr := addr + ptrSize.
   197 
   132     size := self fetchUnboxedIntegerAt:addr.
   198 "/Transcript show:'#'.
   133     addr := addr + ptrSize.
   199 "/Transcript show:((ByteArray new:nBytes-1) replaceFrom:1 to:nBytes-1 with:o startingAt:1) asString.
   134     bits := self fetchUnboxedIntegerAt:addr.
   200 "/Transcript cr.
   135     addr := addr + ptrSize.
   201 
   136 
   202     ] ifFalse:[
   137     self halt.
   203         (flags = Behavior flagNotIndexed) ifFalse:[ 
       
   204             (flags ~= Behavior flagPointers) ifTrue:[
       
   205                 (flags ~= Behavior flagWeakPointers) ifTrue:[
       
   206                     self halt 
       
   207                 ]
       
   208             ].
       
   209         ].
       
   210 
       
   211         nInsts := (size - (intSize * 3)) // intSize.
       
   212         (classRef flags bitTest:Behavior flagBehavior)
       
   213         "/ classRef isImageBehavior 
       
   214         ifTrue:[
       
   215             o := ImageClassObject new:nInsts.
       
   216         ] ifFalse:[
       
   217             o := ImageObject new:nInsts.
       
   218         ].
       
   219         o classRef:classRef.
       
   220 size > 8000 ifTrue:[self halt].
       
   221         o byteSize:size.
       
   222         o bits:bits.
       
   223         addrToObjectMapping at:baseAddr put:o.
       
   224 
       
   225         1 to:nInsts do:[:idx |
       
   226             o at:idx put:(self fetchUnboxedIntegerAt:addr).
       
   227 "/            o at:idx put:(self fetchObjectAt:(self fetchUnboxedIntegerAt:addr)).
       
   228             addr := addr + ptrSize.
       
   229         ]
       
   230     ].
       
   231     o memory:self.
       
   232     ^ o
   138 !
   233 !
   139 
   234 
   140 fetchPointerAt:addr
   235 fetchPointerAt:addr
   141     ^ self fetchUnboxedIntegerAt:addr
   236     ^ self fetchUnboxedIntegerAt:addr
   142 !
   237 !
   143 
   238 
   144 fetchUnboxedIntegerAt:addr
   239 fetchUnboxedIntegerAt:addr
       
   240     |ptr imgAddr|
       
   241 
       
   242     (addr bitAnd:3) ~~ 0 ifTrue:[self halt].
       
   243 
       
   244     imgAddr := self imageAddressOf:addr.
       
   245     stream position:imgAddr.
       
   246     ptr := stream nextUnsignedLongMSB:msb.
       
   247     ^ ptr
       
   248 !
       
   249 
       
   250 imageAddressOf:addr
   145     spaceInfos do:[:eachSpace |
   251     spaceInfos do:[:eachSpace |
   146         |ptr imgAddr|
   252         |byte imgAddr|
   147 
   253 
   148         addr >= eachSpace start ifTrue:[
   254         addr >= eachSpace start ifTrue:[
   149             addr <= eachSpace end ifTrue:[
   255             addr <= eachSpace end ifTrue:[
   150                 imgAddr := eachSpace imageBase + (addr - eachSpace start).
   256                 imgAddr := eachSpace imageBase + (addr - eachSpace start).
   151                 stream position:imgAddr.
   257                 ^ imgAddr
   152                 ptr := stream nextUnsignedLongMSB:msb.
       
   153                 ^ ptr
       
   154             ]
   258             ]
   155         ].
   259         ].
   156     ].
   260     ].
   157     self halt:'image fetch error'.
   261     self halt:'image address error'.
   158 ! !
   262 ! !
   159 
   263 
   160 !SnapShotImageMemory methodsFor:'private'!
   264 !SnapShotImageMemory methodsFor:'private'!
   161 
   265 
   162 allClassesDo:aBlock
   266 allClassesDo:aBlock
   164         |val|
   268         |val|
   165 
   269 
   166         val := self at:eachKey.
   270         val := self at:eachKey.
   167         val isBehavior ifTrue:[
   271         val isBehavior ifTrue:[
   168             aBlock value:val
   272             aBlock value:val
   169         ]
   273         ] ifFalse:[
       
   274             self halt.
       
   275         ].
   170     ].
   276     ].
   171 !
   277 !
   172 
   278 
   173 allGlobalKeysDo:aBlock
   279 allGlobalKeysDo:aBlock
   174     globals isNil ifTrue:[
   280     globalEntries isNil ifTrue:[
   175         self readHeader.
   281         self readHeader.
   176         self readGlobals.
   282         self readGlobals.
   177     ].
   283     ].
       
   284 !
       
   285 
       
   286 fetchStringFor:aStringRef
       
   287     |nBytes|
       
   288 
       
   289     (aStringRef isImageBytes) ifFalse:[self halt].
       
   290 
       
   291     nBytes := aStringRef byteSize - (intSize * 3).
       
   292     ^ ((ByteArray new:nBytes-1) replaceFrom:1 to:nBytes-1 with:aStringRef startingAt:1) asString.
   178 !
   293 !
   179 
   294 
   180 for:aFilename
   295 for:aFilename
   181     stream := aFilename asFilename readStream binary.
   296     stream := aFilename asFilename readStream binary.
   182     addrToObjectMapping := IdentityDictionary new.
   297     addrToObjectMapping := IdentityDictionary new.
       
   298 
       
   299     addrToObjectMapping at:(ObjectMemory addressOf:false) put:false.
       
   300     addrToObjectMapping at:(ObjectMemory addressOf:true) put:true.
       
   301 !
       
   302 
       
   303 printStringOfClass:aClassRef
       
   304     |nameSlot|
       
   305 
       
   306     (aClassRef isImageBehavior) ifFalse:[self halt].
       
   307     ((aClassRef byteSize // intSize) - 3) < Class instSize ifTrue:[self halt.].
       
   308 
       
   309     nameSlot := aClassRef at:7.
       
   310     nameSlot isInteger ifTrue:[
       
   311         nameSlot := self fetchObjectAt:nameSlot
       
   312     ].
       
   313     nameSlot isImageSymbol ifFalse:[self halt].
       
   314     ^ 'Class: ' , (self printStringOfSymbol:nameSlot)
       
   315 !
       
   316 
       
   317 printStringOfObject:anObjectRef
       
   318     |s nBytes|
       
   319 
       
   320     anObjectRef isNil ifTrue:[^ 'nil'].
       
   321     (anObjectRef isInteger) ifTrue:[^ anObjectRef printString].
       
   322     (anObjectRef == true ) ifTrue:[^ anObjectRef printString].
       
   323     (anObjectRef == false) ifTrue:[^ anObjectRef printString].
       
   324 
       
   325     (anObjectRef isImageSymbol) ifTrue:[^ self printStringOfSymbol:anObjectRef].
       
   326     (anObjectRef isImageBehavior) ifTrue:[^ self printStringOfClass:anObjectRef].
       
   327 
       
   328     ^ 'obj(' , anObjectRef printString , ')'
       
   329 !
       
   330 
       
   331 printStringOfString:aStringRef
       
   332     |nBytes|
       
   333 
       
   334     (aStringRef isString) ifFalse:[self halt].
       
   335     ^ self fetchStringFor:aStringRef.
       
   336 !
       
   337 
       
   338 printStringOfSymbol:aSymbolRef
       
   339     |nBytes|
       
   340 
       
   341     (aSymbolRef isImageSymbol) ifFalse:[self halt].
       
   342 ^ self fetchStringFor:aSymbolRef.
       
   343 "/    nBytes := aSymbolRef size - (intSize * 3).
       
   344 "/    ^ ((ByteArray new:nBytes-1) replaceFrom:1 to:nBytes-1 with:aSymbolRef startingAt:1) asString.
   183 !
   345 !
   184 
   346 
   185 readGlobalEntries
   347 readGlobalEntries
   186         |refPointer theSymbol theValue|
   348         |refPointer theSymbolPtr theSymbolRef theValuePtr theValueRef pos|
   187 
   349 
   188         globalEntries := OrderedCollection new.
   350         globalEntries := OrderedCollection new.
   189         [
   351         [
   190             refPointer := stream nextUnsignedLongMSB:msb.
   352             refPointer := stream nextUnsignedLongMSB:msb.
   191             theSymbol := stream nextUnsignedLongMSB:msb.
   353             theSymbolPtr := stream nextUnsignedLongMSB:msb.
   192             theValue := stream nextUnsignedLongMSB:msb.
   354             theValuePtr := stream nextUnsignedLongMSB:msb.
   193             theSymbol ~~ 0
   355             theSymbolPtr ~~ 0
   194         ] whileTrue:[
   356         ] whileTrue:[
   195             globalEntries add:(theSymbol -> theValue).
   357             globalEntries add:(theSymbolPtr -> theValuePtr).
   196         ].
   358         ].
   197         globalEntries := globalEntries asArray
   359         globalEntries := globalEntries asArray.
       
   360 
       
   361 "/ globalEntries inspect.
       
   362         pos := stream position.
       
   363         globalEntries do:[:item |
       
   364             theSymbolPtr := item key.
       
   365             theValuePtr := item value.
       
   366             theSymbolRef := self fetchObjectAt:theSymbolPtr.
       
   367 
       
   368 "/            Transcript show:(self printStringOfSymbol:theSymbolRef).
       
   369 "/            Transcript show:'->'.
       
   370 
       
   371             theValueRef := self fetchObjectAt:theValuePtr.
       
   372 "/            Transcript show:(self printStringOfObject:theValueRef).
       
   373 "/            Transcript cr.
       
   374 
       
   375             item key:theSymbolRef.
       
   376             item value:theValueRef.
       
   377         ].
       
   378         stream position:pos.
   198 !
   379 !
   199 
   380 
   200 readHeader
   381 readHeader
   201         "
   382         "
   202          (self for:'stmeas.img') readHeader
   383          (self for:'stmeas.img') readHeader
   204 
   385 
   205         |order magic version timeStamp snapID last_util_addr hiText_addr flags 
   386         |order magic version timeStamp snapID last_util_addr hiText_addr flags 
   206          lowData hiData charSlots charTableSlots fixMemStart fixMemEnd 
   387          lowData hiData charSlots charTableSlots fixMemStart fixMemEnd 
   207          symMemStart symMemEnd vmDataAddr sharedMethodCode sharedBlockCode 
   388          symMemStart symMemEnd vmDataAddr sharedMethodCode sharedBlockCode 
   208          nContexts contextSpace nRegistered symbolsSeqNr nSpaces 
   389          nContexts contextSpace nRegistered symbolsSeqNr nSpaces 
   209          spaceFlags spaceBase spaceSize classNameSize|
   390          classNameSize spaceSize|
   210 
   391 
   211         stream next:256.        "/ skip execCmd
   392         stream next:256.        "/ skip execCmd
   212 
   393 
   213         msb := false.
   394         msb := false.
   214         order := stream nextUnsignedLongMSB:msb.        
   395         order := stream nextUnsignedLongMSB:msb.        
   275         ].
   456         ].
   276 
   457 
   277         nSpaces := stream nextUnsignedLongMSB:msb.
   458         nSpaces := stream nextUnsignedLongMSB:msb.
   278         spaceInfos := (1 to:nSpaces) collect:[:idx | SpaceInfo new].
   459         spaceInfos := (1 to:nSpaces) collect:[:idx | SpaceInfo new].
   279         
   460         
   280         spaceBase := Array new:nSpaces.
       
   281         spaceSize := Array new:nSpaces.
       
   282         1 to:nSpaces do:[:i |
   461         1 to:nSpaces do:[:i |
   283             (spaceInfos at:i) flags:(stream nextUnsignedLongMSB:msb).
   462             (spaceInfos at:i) flags:(stream nextUnsignedLongMSB:msb).
   284         ].
   463         ].
   285         nSpaces+1 to:32 do:[:i | stream nextUnsignedLongMSB:msb].
   464         nSpaces+1 to:32 do:[:i | stream nextUnsignedLongMSB:msb].
   286 
   465 
   293             (spaceInfos at:i) size:(stream nextUnsignedLongMSB:msb).
   472             (spaceInfos at:i) size:(stream nextUnsignedLongMSB:msb).
   294         ].
   473         ].
   295         nSpaces+1 to:32 do:[:i | stream nextUnsignedLongMSB:msb].
   474         nSpaces+1 to:32 do:[:i | stream nextUnsignedLongMSB:msb].
   296 
   475 
   297         version >= 8 ifTrue:[
   476         version >= 8 ifTrue:[
   298             stream position:(stream class zeroPosition + 4096).
   477             stream position:(stream class zeroPosition).
       
   478             stream skip:4096.
   299         ].
   479         ].
   300 
   480 
   301         1 to:nSpaces do:[:i |
   481         1 to:nSpaces do:[:i |
   302             (spaceInfos at:i) end:((spaceInfos at:i) start + (spaceInfos at:i) size - 1).
   482             (spaceInfos at:i) end:((spaceInfos at:i) start + (spaceInfos at:i) size - 1).
   303         ].
   483         ].
   304         1 to:nSpaces do:[:i |
   484         1 to:nSpaces do:[:i |
   305             (spaceInfos at:i) imageBase:(stream position).
   485             (spaceInfos at:i) imageBase:(stream position).
   306             stream skip:((spaceInfos at:i) size).
   486             spaceSize := (spaceInfos at:i) size.
       
   487             stream skip:spaceSize.
   307         ].
   488         ].
   308 
   489 
   309         "/ registration
   490         "/ registration
   310 
   491 
   311         self readRegistrationEntries.
   492         self readRegistrationEntries.
       
   493         Transcript showCR:'reading symbols...'.
   312         self readSymbolEntries.
   494         self readSymbolEntries.
       
   495         self readUGlobalEntries.
       
   496         Transcript showCR:'reading globals...'.
   313         self readGlobalEntries.
   497         self readGlobalEntries.
   314         self readUGlobalEntries.
       
   315 
   498 
   316 
   499 
   317 "/struct basicImageHeader {
   500 "/struct basicImageHeader {
   318 "/        char            h_execCmd[256];
   501 "/        char            h_execCmd[256];
   319 "/
   502 "/
   452             Transcript showCR:className.
   635             Transcript showCR:className.
   453         ].
   636         ].
   454 !
   637 !
   455 
   638 
   456 readSymbolEntries
   639 readSymbolEntries
   457         |refPointer theSymbol|
   640         |refPointer theSymbolPtr theSymbolRef pos|
   458 
   641 
   459         symbolEntries := OrderedCollection new.
   642         symbolEntries := OrderedCollection new.
   460 
   643 
   461         [
   644         [
   462             refPointer := stream nextUnsignedLongMSB:msb.
   645             refPointer := stream nextUnsignedLongMSB:msb.
   463             theSymbol := stream nextUnsignedLongMSB:msb.
   646             theSymbolPtr := stream nextUnsignedLongMSB:msb.
   464         
   647             theSymbolPtr ~~ 0
   465             theSymbol ~~ 0
       
   466         ] whileTrue:[
   648         ] whileTrue:[
   467             symbolEntries add:(theSymbol -> refPointer).
   649             symbolEntries add:theSymbolPtr.
   468         ].
   650         ].
   469         symbolEntries := symbolEntries asArray
   651         symbolEntries := symbolEntries asArray.
       
   652 
       
   653         pos := stream position.
       
   654         symbolEntries := symbolEntries collect:[:theSymbolPtr |
       
   655             theSymbolRef := self fetchObjectAt:theSymbolPtr.
       
   656             theSymbolRef isImageSymbol ifFalse:[
       
   657                 self halt
       
   658             ].
       
   659         ].        
       
   660         stream position:pos
   470 !
   661 !
   471 
   662 
   472 readUGlobalEntries
   663 readUGlobalEntries
   473         |refPointer theValue|
   664         |refPointer theValue|
   474 
   665 
   477             theValue := stream nextUnsignedLongMSB:msb.
   668             theValue := stream nextUnsignedLongMSB:msb.
   478             refPointer ~~ 0
   669             refPointer ~~ 0
   479         ] whileTrue
   670         ] whileTrue
   480 ! !
   671 ! !
   481 
   672 
       
   673 !SnapShotImageMemory::ImageHeader methodsFor:'accessing'!
       
   674 
       
   675 bits
       
   676     "return the value of the instance variable 'bits' (automatically generated)"
       
   677 
       
   678     ^ bits!
       
   679 
       
   680 bits:something
       
   681     "set the value of the instance variable 'bits' (automatically generated)"
       
   682 
       
   683     bits := something.!
       
   684 
       
   685 byteSize
       
   686     "return the value of the instance variable 'size' (automatically generated)"
       
   687 
       
   688     ^ byteSize
       
   689 !
       
   690 
       
   691 byteSize:something
       
   692     "set the value of the instance variable 'size' (automatically generated)"
       
   693 
       
   694 something > 8000 ifTrue:[self halt].
       
   695     byteSize := something.
       
   696 !
       
   697 
       
   698 classRef
       
   699     "return the value of the instance variable 'classRef' (automatically generated)"
       
   700 
       
   701     ^ classRef!
       
   702 
       
   703 classRef:something
       
   704     "set the value of the instance variable 'classRef' (automatically generated)"
       
   705 
       
   706     classRef := something.!
       
   707 
       
   708 memory
       
   709     "return the value of the instance variable 'memory' (automatically generated)"
       
   710 
       
   711     ^ memory!
       
   712 
       
   713 memory:something
       
   714     "set the value of the instance variable 'memory' (automatically generated)"
       
   715 
       
   716     memory := something.! !
       
   717 
       
   718 !SnapShotImageMemory::ImageHeader methodsFor:'queries'!
       
   719 
       
   720 category
       
   721     |categoryPtr categoryRef category|
       
   722 
       
   723     self isMethodOrLazyMethod ifTrue:[
       
   724         categoryPtr := self at:6.
       
   725         categoryRef := memory fetchObjectAt:categoryPtr.
       
   726         category := memory fetchStringFor:categoryRef.
       
   727         ^ category
       
   728     ].
       
   729 self halt.
       
   730 !
       
   731 
       
   732 isImageBehavior
       
   733     |flags|
       
   734 
       
   735     flags := classRef flags.
       
   736     ^ flags bitTest:Behavior flagBehavior  
       
   737 !
       
   738 
       
   739 isImageBytes
       
   740     |flags|
       
   741 
       
   742     flags := classRef flags bitAnd:Behavior maskIndexType.
       
   743     ^ flags = Behavior flagBytes 
       
   744 !
       
   745 
       
   746 isImageMethod
       
   747     |flags|
       
   748 
       
   749     flags := classRef flags.
       
   750     ^ flags bitTest:Behavior flagMethod 
       
   751 !
       
   752 
       
   753 isImageSymbol
       
   754     |flags|
       
   755 
       
   756     flags := classRef flags.
       
   757     ^ flags bitTest:Behavior flagSymbol 
       
   758 !
       
   759 
       
   760 isMeta
       
   761     ^ false
       
   762 !
       
   763 
       
   764 isMethod                               
       
   765     ^ classRef name = 'Method'
       
   766 !
       
   767 
       
   768 isMethodDictionary
       
   769     ^ classRef name = 'MethodDictionary'
       
   770 !
       
   771 
       
   772 isMethodOrLazyMethod                 
       
   773     classRef name = 'LazyMethod' ifTrue:[^ true].
       
   774     ^ classRef name = 'Method'
       
   775 !
       
   776 
       
   777 isString                               
       
   778     ^ classRef name = 'String'
       
   779 ! !
       
   780 
   482 !SnapShotImageMemory::SpaceInfo methodsFor:'accessing'!
   781 !SnapShotImageMemory::SpaceInfo methodsFor:'accessing'!
   483 
   782 
   484 end
   783 end
   485     "return the value of the instance variable 'end' (automatically generated)"
   784     "return the value of the instance variable 'end' (automatically generated)"
   486 
   785 
   529 start:something
   828 start:something
   530     "set the value of the instance variable 'start' (automatically generated)"
   829     "set the value of the instance variable 'start' (automatically generated)"
   531 
   830 
   532     start := something.! !
   831     start := something.! !
   533 
   832 
   534 !SnapShotImageMemory::ImageObject methodsFor:'accessing'!
   833 !SnapShotImageMemory::ImageObject methodsFor:'object protocol'!
   535 
   834 
   536 bits
   835 at:aSelector ifAbsent:exceptionValue
   537     "return the value of the instance variable 'bits' (automatically generated)"
   836     |symPtr symRef mthdPtr mthdRef s|
   538 
   837 
   539     ^ bits!
   838     self isMethodDictionary ifTrue:[
   540 
   839         1 to:self size by:2 do:[:idx |
   541 bits:something
   840             symPtr := self at:idx.
   542     "set the value of the instance variable 'bits' (automatically generated)"
   841             symRef := memory fetchObjectAt:symPtr.
   543 
   842             symRef isImageSymbol ifFalse:[self halt].
   544     bits := something.!
   843             s := memory fetchStringFor:symRef.
   545 
   844             mthdPtr := self at:idx + 1.
   546 classRef
   845             mthdRef := memory fetchObjectAt:mthdPtr.
   547     "return the value of the instance variable 'classRef' (automatically generated)"
   846             ^ mthdRef.
   548 
   847         ].
   549     ^ classRef!
   848     ].
   550 
   849     ^ exceptionValue value
   551 classRef:something
   850 !
   552     "set the value of the instance variable 'classRef' (automatically generated)"
   851 
   553 
   852 do:aBlock
   554     classRef := something.!
   853     |mthdPtr mthdRef|
   555 
   854 
   556 size
   855     self isMethodDictionary ifTrue:[
   557     "return the value of the instance variable 'size' (automatically generated)"
   856         2 to:self size by:2 do:[:idx |
   558 
   857             mthdPtr := self at:idx.
   559     ^ size!
   858             mthdRef := memory fetchObjectAt:mthdPtr.
   560 
   859             aBlock value:mthdRef.
   561 size:something
   860         ].
   562     "set the value of the instance variable 'size' (automatically generated)"
   861     ].
   563 
   862 !
   564     size := something.! !
   863 
   565 
   864 isWrapped
   566 !SnapShotImageMemory::ImageObject methodsFor:'queries'!
   865     ^ false
   567 
   866 !
   568 isImageBehavior
   867 
       
   868 keysAndValuesDo:aBlock
       
   869     |symPtr symRef mthdPtr mthdRef s|
       
   870 
       
   871     self isMethodDictionary ifTrue:[
       
   872         1 to:self size by:2 do:[:idx |
       
   873             symPtr := self at:idx.
       
   874             symRef := memory fetchObjectAt:symPtr.
       
   875             symRef isImageSymbol ifFalse:[self halt].
       
   876             s := memory fetchStringFor:symRef.
       
   877             mthdPtr := self at:idx + 1.
       
   878             mthdRef := memory fetchObjectAt:mthdPtr.
       
   879             aBlock value:s asSymbol value:mthdRef.
       
   880         ].
       
   881     ].
       
   882 !
       
   883 
       
   884 printStringForBrowserWithSelector:selector
       
   885     ^ selector
       
   886 !
       
   887 
       
   888 resources
       
   889     ^ nil
       
   890 !
       
   891 
       
   892 source
       
   893     |sourcePosition source aStream junk|
       
   894 
       
   895     self isMethod ifTrue:[
       
   896         sourcePosition := self at:(Method instVarOffsetOf:'sourcePosition').
       
   897         source := self at:(Method instVarOffsetOf:'source').
       
   898         source := memory fetchObjectAt:source.
       
   899         source isString ifFalse:[
       
   900             self halt.
       
   901         ].
       
   902         source := memory printStringOfString:source.
       
   903         sourcePosition isNil ifTrue:[
       
   904             self halt.
       
   905             ^ source
       
   906         ].
       
   907         sourcePosition := memory fetchObjectAt:sourcePosition.
       
   908 
       
   909         aStream := self sourceStream.
       
   910         aStream notNil ifTrue:[
       
   911             Stream positionErrorSignal handle:[:ex |
       
   912                 ^ nil
       
   913             ] do:[
       
   914                 aStream position:sourcePosition abs.
       
   915             ].
       
   916             junk := aStream nextChunk.
       
   917 
       
   918             aStream close.
       
   919             ^ junk
       
   920         ].
       
   921     ].
       
   922     self halt.
       
   923 !
       
   924 
       
   925 sourceStream
       
   926     |sourcePosition source aStream fileName junk who 
       
   927      myClass mgr className sep dir mod package|
       
   928 
       
   929     self isMethod ifTrue:[
       
   930         sourcePosition := self at:(Method instVarOffsetOf:'sourcePosition').
       
   931         source := self at:(Method instVarOffsetOf:'source').
       
   932         source := memory fetchObjectAt:source.
       
   933         source isString ifTrue:[
       
   934             source := memory printStringOfString:source.
       
   935         ].
       
   936         sourcePosition notNil ifTrue:[
       
   937             sourcePosition := memory fetchObjectAt:sourcePosition.
       
   938         ].
       
   939 
       
   940         source isNil ifTrue:[^ nil].
       
   941         sourcePosition isNil ifTrue:[^ source readStream].
       
   942 
       
   943         sourcePosition < 0 ifTrue:[
       
   944             aStream := source asFilename readStream.
       
   945             aStream notNil ifTrue:[
       
   946                 ^ aStream
       
   947             ].
       
   948 
       
   949             fileName := Smalltalk getSourceFileName:source.
       
   950             fileName notNil ifTrue:[
       
   951                 aStream := fileName asFilename readStream.
       
   952                 aStream notNil ifTrue:[
       
   953                     ^ aStream
       
   954                 ].
       
   955             ].
       
   956         ].
       
   957 
       
   958         "/
       
   959         "/ if there is no SourceManager, look in local standard places first
       
   960         "/
       
   961         (mgr := Smalltalk at:#SourceCodeManager) isNil ifTrue:[
       
   962             aStream := self localSourceStream.
       
   963             aStream notNil ifTrue:[
       
   964                 ^ aStream
       
   965             ].
       
   966         ].
       
   967 
       
   968         "/
       
   969         "/ nope - ask my class for the source (this also invokes the SCMgr)
       
   970         "/
       
   971         myClass := self mclass.
       
   972 
       
   973         package := self package.
       
   974         (package notNil and:[package ~= myClass package]) ifTrue:[
       
   975             mgr notNil ifTrue:[
       
   976                 "/ try to get the source using my package information ...
       
   977                 sep := package indexOfAny:'/\:'.
       
   978                 sep ~~ 0 ifTrue:[
       
   979                     mod := package copyTo:sep - 1.
       
   980                     dir := package copyFrom:sep + 1.
       
   981                     aStream := mgr streamForClass:nil fileName:source revision:nil directory:dir module:mod cache:true.
       
   982                     aStream notNil ifTrue:[
       
   983                         ^ aStream
       
   984                     ].
       
   985                 ].
       
   986             ].
       
   987         ].
       
   988 
       
   989         aStream := myClass sourceStreamFor:source.
       
   990         aStream notNil ifTrue:[
       
   991             ^ aStream
       
   992         ].
       
   993 
       
   994         "/
       
   995         "/ nope - look in standard places 
       
   996         "/ (if there is a source-code manager - otherwise, we already did that)
       
   997         "/
       
   998         mgr notNil ifTrue:[
       
   999             aStream := self localSourceStream.
       
  1000             aStream notNil ifTrue:[
       
  1001                 ^ aStream
       
  1002             ].
       
  1003         ].
       
  1004 
       
  1005         "/
       
  1006         "/ final chance: try current directory
       
  1007         "/
       
  1008         aStream isNil ifTrue:[
       
  1009             aStream := source asFilename readStream.
       
  1010             aStream notNil ifTrue:[
       
  1011                 ^ aStream
       
  1012             ].
       
  1013         ].
       
  1014 
       
  1015         (who isNil and:[source notNil]) ifTrue:[
       
  1016             "/
       
  1017             "/ mhmh - seems to be a method which used to be in some
       
  1018             "/ class, but has been overwritten by another or removed.
       
  1019             "/ (i.e. it has no containing class anyMore)
       
  1020             "/ try to guess the class from the sourceFileName.
       
  1021             "/ and retry.
       
  1022             "/
       
  1023             className := Smalltalk classNameForFile:source.
       
  1024             className knownAsSymbol ifTrue:[
       
  1025                 myClass := Smalltalk at:className asSymbol ifAbsent:nil.
       
  1026                 myClass notNil ifTrue:[
       
  1027                     aStream := myClass sourceStreamFor:source.
       
  1028                     aStream notNil ifTrue:[
       
  1029                         ^ aStream
       
  1030                     ].
       
  1031                 ]
       
  1032             ]
       
  1033         ].                
       
  1034 
       
  1035         ^ nil
       
  1036     ].
       
  1037     self halt.
       
  1038 ! !
       
  1039 
       
  1040 !SnapShotImageMemory::ImageClassObject methodsFor:'accessing - slots'!
       
  1041 
       
  1042 category
       
  1043     |categoryRef category|
       
  1044 
       
  1045     categoryRef := self categorySlot.
       
  1046     categoryRef isInteger ifTrue:[
       
  1047         categoryRef := memory fetchObjectAt:categoryRef.
       
  1048     ].
       
  1049     categoryRef notNil ifTrue:[
       
  1050         category := memory fetchStringFor:categoryRef.
       
  1051     ].
       
  1052     ^ category
       
  1053 !
       
  1054 
       
  1055 categorySlot
       
  1056     ^ self at:8
       
  1057 !
       
  1058 
       
  1059 classFilenameSlot
       
  1060     ^ self at:12
       
  1061 !
       
  1062 
       
  1063 classVarNames
       
  1064     |classVarNamesRef classVarNames s|
       
  1065 
       
  1066     classVarNamesRef := self classVarsSlot.
       
  1067     classVarNamesRef isInteger ifTrue:[
       
  1068         classVarNamesRef := memory fetchObjectAt:classVarNamesRef.
       
  1069     ].
       
  1070     classVarNamesRef notNil ifTrue:[
       
  1071         classVarNamesRef isImageBytes ifTrue:[
       
  1072             "/ a string
       
  1073             classVarNames := memory fetchStringFor:classVarNamesRef.
       
  1074             classVarNames := classVarNames asCollectionOfWords.
       
  1075         ] ifFalse:[
       
  1076             classVarNames := Array new:(classVarNamesRef size).
       
  1077             1 to:classVarNames size do:[:idx |
       
  1078                 s := classVarNamesRef at:idx.
       
  1079                 s := memory fetchObjectAt:s.
       
  1080                 s isImageBytes ifFalse:[self halt].
       
  1081                 s := memory fetchStringFor:s.
       
  1082                 classVarNames at:idx put:s.
       
  1083             ].
       
  1084         ].
       
  1085     ].
       
  1086     ^ classVarNames
       
  1087 !
       
  1088 
       
  1089 classVarsSlot
       
  1090     ^ self at:9
       
  1091 !
       
  1092 
       
  1093 comment
       
  1094     |commentRef comment|
       
  1095 
       
  1096     commentRef := self commentSlot.
       
  1097     commentRef isInteger ifTrue:[
       
  1098         commentRef := memory fetchObjectAt:commentRef.
       
  1099     ].
       
  1100     commentRef notNil ifTrue:[
       
  1101         comment := memory fetchStringFor:commentRef.
       
  1102     ].
       
  1103     ^ comment
       
  1104 !
       
  1105 
       
  1106 commentSlot
       
  1107     ^ self at:10
       
  1108 !
       
  1109 
       
  1110 flags
   569     |flags|
  1111     |flags|
   570 
  1112 
   571     flags := self flagsSlot.
  1113     flags := self flagsSlot.
   572 
  1114 
   573     (SnapShotImageMemory isSmallIntegerOOP:flags) ifFalse:[
  1115     (SnapShotImageMemory isSmallIntegerOOP:flags) ifFalse:[
   574         self halt
  1116         self halt
   575     ].
  1117     ].
   576     flags := flags bitShift:-1.
  1118     ^ flags bitShift:-1.
   577     ^ flags bitTest:Behavior flagBehavior  
       
   578 !
       
   579 
       
   580 isImageBytes
       
   581     self halt.
       
   582 !
       
   583 
       
   584 isImageString
       
   585     self halt.
       
   586 !
       
   587 
       
   588 isImageSymbol
       
   589     self halt.
       
   590 ! !
       
   591 
       
   592 !SnapShotImageMemory::ImageClassObject methodsFor:'accessing - slots'!
       
   593 
       
   594 categorySlot
       
   595     ^ self at:8
       
   596 !
       
   597 
       
   598 classFilenameSlot
       
   599     ^ self at:12
       
   600 !
       
   601 
       
   602 classVarsSlot
       
   603     ^ self at:9
       
   604 !
       
   605 
       
   606 commentSlot
       
   607     ^ self at:10
       
   608 !
  1119 !
   609 
  1120 
   610 flagsSlot
  1121 flagsSlot
   611     ^ self at:2
  1122     ^ self at:2
   612 !
  1123 !
   613 
  1124 
   614 flagsValue
       
   615     |flags|
       
   616 
       
   617     flags := self flagsSlot.
       
   618 
       
   619     (SnapShotImageMemory isSmallIntegerOOP:flags) ifFalse:[
       
   620         self halt
       
   621     ].
       
   622     ^ flags bitShift:-1.
       
   623 !
       
   624 
       
   625 instSizeSlot
  1125 instSizeSlot
   626     ^ self at:5
  1126     ^ self at:5
   627 !
  1127 !
   628 
  1128 
       
  1129 instVarNames
       
  1130     |instVarNamesRef instVarNames s|
       
  1131 
       
  1132     instVarNamesRef := self instVarsSlot.
       
  1133     instVarNamesRef isInteger ifTrue:[
       
  1134         instVarNamesRef := memory fetchObjectAt:instVarNamesRef.
       
  1135     ].
       
  1136     instVarNamesRef notNil ifTrue:[
       
  1137         instVarNamesRef isImageBytes ifTrue:[
       
  1138             "/ a string
       
  1139             instVarNames := memory fetchStringFor:instVarNamesRef.
       
  1140             instVarNames := instVarNames asCollectionOfWords.
       
  1141         ] ifFalse:[
       
  1142             instVarNames := Array new:(instVarNamesRef size).
       
  1143             1 to:instVarNames size do:[:idx |
       
  1144                 s := instVarNamesRef at:idx.
       
  1145                 s := memory fetchObjectAt:s.
       
  1146                 s isImageBytes ifFalse:[self halt].
       
  1147                 s := memory fetchStringFor:s.
       
  1148                 instVarNames at:idx put:s.
       
  1149             ].
       
  1150         ].
       
  1151     ].
       
  1152     ^ instVarNames
       
  1153 !
       
  1154 
   629 instVarsSlot
  1155 instVarsSlot
   630     ^ self at:6
  1156     ^ self at:6
   631 !
  1157 !
   632 
  1158 
       
  1159 methodDictionary
       
  1160     |methodDictionaryRef methodDictionary|
       
  1161 
       
  1162     methodDictionaryRef := self methodDictionarySlot.
       
  1163     methodDictionaryRef isInteger ifTrue:[
       
  1164         methodDictionaryRef == 0 ifTrue:[^ nil].
       
  1165         methodDictionary := memory fetchObjectAt:methodDictionaryRef.
       
  1166     ].
       
  1167     ^ methodDictionary
       
  1168 !
       
  1169 
   633 methodDictionarySlot
  1170 methodDictionarySlot
   634     ^ self at:3
  1171     ^ self at:3
   635 !
  1172 !
   636 
  1173 
       
  1174 name
       
  1175     |nameRef name|
       
  1176 
       
  1177     nameRef := self nameSlot.
       
  1178     nameRef isInteger ifTrue:[
       
  1179         nameRef := memory fetchObjectAt:nameRef.
       
  1180     ].
       
  1181     nameRef notNil ifTrue:[
       
  1182         name := memory fetchStringFor:nameRef.
       
  1183     ].
       
  1184     nameRef notNil ifTrue:[
       
  1185         name := name asSymbol.
       
  1186     ].
       
  1187     ^ name
       
  1188 !
       
  1189 
   637 nameSlot
  1190 nameSlot
   638     ^ self at:7
  1191     ^ self at:7
   639 !
  1192 !
   640 
  1193 
   641 packageSlot
  1194 packageSlot
   644 
  1197 
   645 revisionSlot
  1198 revisionSlot
   646     ^ self at:14
  1199     ^ self at:14
   647 !
  1200 !
   648 
  1201 
   649 superClassSlot
  1202 superclass
       
  1203     |superClassRef superClass|
       
  1204 
       
  1205     superClassRef := self superclassSlot.
       
  1206     superClassRef isInteger ifTrue:[
       
  1207         superClass := memory fetchObjectAt:superClassRef.
       
  1208     ].
       
  1209     ^ superClass
       
  1210 !
       
  1211 
       
  1212 superclassSlot
   650     ^ self at:1
  1213     ^ self at:1
       
  1214 ! !
       
  1215 
       
  1216 !SnapShotImageMemory::ImageClassObject methodsFor:'class protocol'!
       
  1217 
       
  1218 basicFileOutDefinitionOn:aStream withNameSpace:forceNameSpace withPackage:showPackage
       
  1219     "append an expression on aStream, which defines myself."
       
  1220 
       
  1221     |s owner ns nsName fullName superName cls topOwner
       
  1222      syntaxHilighting superclass category|
       
  1223 
       
  1224     superclass := self superclass.
       
  1225     category := self category.
       
  1226 
       
  1227     UserPreferences isNil ifTrue:[
       
  1228         syntaxHilighting := false
       
  1229     ] ifFalse:[
       
  1230         syntaxHilighting := UserPreferences current syntaxColoring.
       
  1231     ].
       
  1232 
       
  1233     owner := self owningClass.
       
  1234 
       
  1235     owner isNil ifTrue:[
       
  1236         ns := self nameSpace.
       
  1237     ] ifFalse:[
       
  1238         ns := self topOwningClass nameSpace
       
  1239     ].
       
  1240     fullName := Class fileOutNameSpaceQuerySignal query == true.
       
  1241 
       
  1242     (showPackage and:[owner isNil]) ifTrue:[
       
  1243         aStream nextPutAll:'"{ Package: '''.
       
  1244         aStream nextPutAll:self package asString.
       
  1245         aStream nextPutAll:''' }"'; cr; cr.
       
  1246     ].
       
  1247 
       
  1248     ((owner isNil and:[fullName not])
       
  1249     or:[owner notNil and:[forceNameSpace and:[fullName not]]]) ifTrue:[
       
  1250         (ns notNil and:[ns ~~ Smalltalk]) ifTrue:[
       
  1251             nsName := ns name.
       
  1252             (nsName includes:$:) ifTrue:[
       
  1253                 nsName := '''' , nsName , ''''
       
  1254             ].
       
  1255 "/            aStream nextPutLine:'"{ NameSpace: ' , nsName , ' }"'; cr.
       
  1256             aStream nextPutAll:'"{ NameSpace: '.
       
  1257             syntaxHilighting ifTrue:[aStream bold].
       
  1258             aStream nextPutAll:nsName.
       
  1259             syntaxHilighting ifTrue:[aStream normal].
       
  1260             aStream nextPutAll:' }"'; cr; cr.
       
  1261         ]
       
  1262     ].
       
  1263 
       
  1264     "take care of nil-superclass"
       
  1265     superclass isNil ifTrue:[
       
  1266         s := 'nil'
       
  1267     ] ifFalse:[
       
  1268         fullName ifTrue:[
       
  1269             superclass == owner ifTrue:[
       
  1270                 s := superclass nameWithoutNameSpacePrefix
       
  1271             ] ifFalse:[
       
  1272                 s := superclass name
       
  1273             ]
       
  1274         ] ifFalse:[
       
  1275             (ns == superclass nameSpace 
       
  1276             and:[superclass owningClass isNil]) ifTrue:[
       
  1277                 "/ superclass is in the same namespace;
       
  1278                 "/ still prepend namespace prefix, to avoid
       
  1279                 "/ confusing stc, which needs that information ...
       
  1280                 s := superclass nameWithoutPrefix
       
  1281             ] ifFalse:[
       
  1282                 "/ a very special (rare) situation:
       
  1283                 "/ my superclass resides in another nameSpace,
       
  1284                 "/ but there is something else named like this
       
  1285                 "/ to be found in my nameSpace (or a private class)
       
  1286 
       
  1287                 superName := superclass nameWithoutNameSpacePrefix asSymbol.
       
  1288                 cls := self privateClassesAt:superName.
       
  1289                 cls isNil ifTrue:[
       
  1290                     (topOwner := self topOwningClass) isNil ifTrue:[
       
  1291                         ns := self nameSpace.
       
  1292                         ns notNil ifTrue:[
       
  1293                             cls := ns privateClassesAt:superName
       
  1294                         ] ifFalse:[
       
  1295                             "/ self error:'unexpected nil namespace'
       
  1296                         ]
       
  1297                     ] ifFalse:[
       
  1298                         cls := topOwner nameSpace at:superName.
       
  1299                     ]
       
  1300                 ].
       
  1301                 (cls notNil and:[cls ~~ superclass]) ifTrue:[
       
  1302                     s := superclass nameSpace name , '::' , superName
       
  1303                 ] ifFalse:[
       
  1304                     "/ no class with that name found in my namespace ...
       
  1305                     "/ if the superclass resides in Smalltalk,
       
  1306                     "/ suppress prefix; otherwise, use full prefix.
       
  1307                     (superclass nameSpace notNil 
       
  1308                     and:[superclass nameSpace ~~ Smalltalk]) ifTrue:[
       
  1309                         (owner notNil 
       
  1310                         and:[owner nameSpace == superclass owningClass nameSpace])
       
  1311                         ifTrue:[
       
  1312                             s := superclass nameWithoutNameSpacePrefix
       
  1313                         ] ifFalse:[
       
  1314                             s := superclass name
       
  1315                         ]
       
  1316                     ] ifFalse:[
       
  1317                         s := superName
       
  1318                     ]
       
  1319                 ]
       
  1320             ]
       
  1321         ]
       
  1322     ].
       
  1323 
       
  1324     syntaxHilighting ifTrue:[aStream bold].
       
  1325     aStream nextPutAll:s.   "/ superclass
       
  1326     syntaxHilighting ifTrue:[aStream normal].
       
  1327     aStream space.
       
  1328     self basicFileOutInstvarTypeKeywordOn:aStream.
       
  1329 
       
  1330     (fullName and:[owner isNil]) ifTrue:[
       
  1331         aStream nextPutAll:'#'''.
       
  1332         syntaxHilighting ifTrue:[aStream bold].
       
  1333         aStream nextPutAll:(self name).
       
  1334         syntaxHilighting ifTrue:[aStream normal].
       
  1335         aStream nextPutAll:''''.
       
  1336     ] ifFalse:[
       
  1337         aStream nextPut:$#.
       
  1338         syntaxHilighting ifTrue:[aStream bold].
       
  1339         aStream nextPutAll:(self nameWithoutPrefix).
       
  1340         syntaxHilighting ifTrue:[aStream normal].
       
  1341     ].
       
  1342 
       
  1343     aStream crtab. 
       
  1344     aStream nextPutAll:'instanceVariableNames:'''.
       
  1345     syntaxHilighting ifTrue:[aStream bold].
       
  1346     self printInstVarNamesOn:aStream indent:16.
       
  1347     syntaxHilighting ifTrue:[aStream normal].
       
  1348     aStream nextPutAll:''''.
       
  1349 
       
  1350     aStream crtab.
       
  1351     aStream nextPutAll:'classVariableNames:'''.
       
  1352     syntaxHilighting ifTrue:[aStream bold].
       
  1353     self printClassVarNamesOn:aStream indent:16.
       
  1354     syntaxHilighting ifTrue:[aStream normal].
       
  1355     aStream nextPutAll:''''.
       
  1356 
       
  1357     aStream crtab.
       
  1358     aStream nextPutAll:'poolDictionaries:'''''.
       
  1359 
       
  1360     aStream crtab.
       
  1361     owner isNil ifTrue:[
       
  1362         "/ a public class
       
  1363         aStream nextPutAll:'category:'.
       
  1364         category isNil ifTrue:[
       
  1365             s := ''''''
       
  1366         ] ifFalse:[
       
  1367             s := category asString storeString
       
  1368         ].
       
  1369         aStream nextPutAll:s.
       
  1370     ] ifFalse:[
       
  1371         "/ a private class
       
  1372         aStream nextPutAll:'privateIn:'.
       
  1373         syntaxHilighting ifTrue:[aStream bold].
       
  1374 "/        fullName ifTrue:[
       
  1375 "/            s := owner name.
       
  1376 "/        ] ifFalse:[
       
  1377 "/            s := owner nameWithoutNameSpacePrefix.
       
  1378 "/        ].
       
  1379         s := owner nameWithoutNameSpacePrefix.
       
  1380         aStream nextPutAll:s.
       
  1381         syntaxHilighting ifTrue:[aStream normal].
       
  1382     ].
       
  1383     aStream cr
       
  1384 
       
  1385     "Created: / 4.1.1997 / 20:38:16 / cg"
       
  1386     "Modified: / 8.8.1997 / 10:59:50 / cg"
       
  1387     "Modified: / 18.3.1999 / 18:15:46 / stefan"
       
  1388 !
       
  1389 
       
  1390 basicFileOutInstvarTypeKeywordOn:aStream
       
  1391     "a helper for fileOutDefinition"
       
  1392 
       
  1393     |isVar s superclass|
       
  1394 
       
  1395     superclass := self superclass.
       
  1396     superclass isNil ifTrue:[
       
  1397         isVar := self isVariable
       
  1398     ] ifFalse:[
       
  1399         "I cant remember what this is for ?"
       
  1400         isVar := (self isVariable and:[superclass isVariable not])
       
  1401     ].
       
  1402 
       
  1403     aStream nextPutAll:(self firstDefinitionSelectorPart).
       
  1404 
       
  1405     "Created: 11.10.1996 / 18:57:29 / cg"
       
  1406 !
       
  1407 
       
  1408 compiledMethodAt:aSelector
       
  1409 
       
  1410     ^ self compiledMethodAt:aSelector ifAbsent:nil
       
  1411 !
       
  1412 
       
  1413 compiledMethodAt:aSelector ifAbsent:exceptionValue
       
  1414     |dict|
       
  1415 
       
  1416     dict := self methodDictionary.
       
  1417     dict isNil ifTrue:[
       
  1418         ('Behavior [warning]: nil methodDictionary in ' , self name printString) errorPrintCR.
       
  1419         ^ exceptionValue value
       
  1420     ].
       
  1421 
       
  1422     ^ dict at:aSelector ifAbsent:exceptionValue
       
  1423 !
       
  1424 
       
  1425 evaluatorClass
       
  1426     ^ Object evaluatorClass
       
  1427 !
       
  1428 
       
  1429 firstDefinitionSelectorPart
       
  1430     "return the first part of the selector with which I was (can be) defined in my superclass"
       
  1431 
       
  1432     self isVariable ifFalse:[
       
  1433         ^ #'subclass:'
       
  1434     ].
       
  1435     self isBytes ifTrue:[
       
  1436         ^ #'variableByteSubclass:'
       
  1437     ].
       
  1438     self isLongs ifTrue:[
       
  1439         ^ #'variableLongSubclass:'
       
  1440     ].
       
  1441     self isFloats ifTrue:[
       
  1442         ^ #'variableFloatSubclass:'
       
  1443     ].
       
  1444     self isDoubles ifTrue:[
       
  1445         ^ #'variableDoubleSubclass:'
       
  1446     ].
       
  1447     self isWords ifTrue:[
       
  1448         ^ #'variableWordSubclass:'
       
  1449     ].
       
  1450     self isSignedWords ifTrue:[
       
  1451         ^ #'variableSignedWordSubclass:'
       
  1452     ].
       
  1453     self isSignedLongs ifTrue:[
       
  1454         ^ #'variableSignedLongSubclass:'
       
  1455     ].
       
  1456     self isSignedLongLongs ifTrue:[
       
  1457         ^ #'variableSignedLongLongSubclass:'
       
  1458     ].
       
  1459     self isLongLongs ifTrue:[
       
  1460         ^ #'variableLongLongSubclass:'
       
  1461     ].
       
  1462     ^ #'variableSubclass:'
       
  1463 !
       
  1464 
       
  1465 nameWithoutNameSpacePrefix
       
  1466     |nm owner|
       
  1467 
       
  1468     nm := self nameWithoutPrefix.
       
  1469     (owner := self owningClass) isNil ifTrue:[
       
  1470         ^ nm
       
  1471     ].
       
  1472 
       
  1473     ^ (owner nameWithoutNameSpacePrefix , '::' , nm)
       
  1474 !
       
  1475 
       
  1476 nameWithoutPrefix
       
  1477     |nm idx|
       
  1478 
       
  1479     nm := self name.
       
  1480     idx := nm lastIndexOf:$:.
       
  1481     idx == 0 ifTrue:[
       
  1482         ^ nm
       
  1483     ].
       
  1484     ^ nm copyFrom:idx+1.
       
  1485 !
       
  1486 
       
  1487 printClassVarNamesOn:aStream indent:indent
       
  1488     "print the class variable names indented and breaking at line end"
       
  1489 
       
  1490     self printNameArray:(self classVarNames) on:aStream indent:indent
       
  1491 !
       
  1492 
       
  1493 printHierarchyAnswerIndentOn:aStream
       
  1494     "print my class hierarchy on aStream - return indent
       
  1495      recursively calls itself to print superclass and use returned indent
       
  1496      for my description - used in the browser"
       
  1497 
       
  1498     |indent nm superclass|
       
  1499 
       
  1500     superclass := self superclass.
       
  1501     indent := 0.
       
  1502     (superclass notNil) ifTrue:[
       
  1503         indent := (superclass printHierarchyAnswerIndentOn:aStream) + 2
       
  1504     ].
       
  1505     aStream spaces:indent.
       
  1506     nm := self printNameInHierarchy.
       
  1507     aStream nextPutAll:nm; nextPutAll:' ('.
       
  1508     self printInstVarNamesOn:aStream indent:(indent + nm size + 2).
       
  1509     aStream nextPutLine:')'.
       
  1510     ^ indent
       
  1511 !
       
  1512 
       
  1513 printHierarchyOn:aStream
       
  1514     self printHierarchyAnswerIndentOn:aStream
       
  1515 !
       
  1516 
       
  1517 printInstVarNamesOn:aStream indent:indent
       
  1518     "print the instance variable names indented and breaking at line end"
       
  1519 
       
  1520     self printNameArray:(self instVarNames) on:aStream indent:indent
       
  1521 
       
  1522     "Created: 22.3.1997 / 14:12:00 / cg"
       
  1523 !
       
  1524 
       
  1525 printNameArray:anArray on:aStream indent:indent
       
  1526     "print an array of strings separated by spaces; when the stream
       
  1527      defines a lineLength, break when this limit is reached; indent
       
  1528      every line; used to printOut instance variable names"
       
  1529 
       
  1530     |thisName nextName arraySize lenMax pos mustBreak line spaces|
       
  1531 
       
  1532     arraySize := anArray size.
       
  1533     arraySize ~~ 0 ifTrue:[
       
  1534         pos := indent.
       
  1535         lenMax := aStream lineLength.
       
  1536         thisName := anArray at:1.
       
  1537         line := ''.
       
  1538         1 to:arraySize do:[:index |
       
  1539             line := line , thisName.
       
  1540             pos := pos + thisName size.
       
  1541             (index == arraySize) ifFalse:[
       
  1542                 nextName := anArray at:(index + 1).
       
  1543                 mustBreak := false.
       
  1544                 (lenMax > 0) ifTrue:[
       
  1545                     ((pos + nextName size) > lenMax) ifTrue:[
       
  1546                         mustBreak := true
       
  1547                     ]
       
  1548                 ].
       
  1549                 mustBreak ifTrue:[
       
  1550                     aStream nextPutLine:line withTabs.
       
  1551                     spaces isNil ifTrue:[
       
  1552                         spaces := String new:indent
       
  1553                     ].
       
  1554                     line := spaces.
       
  1555                     pos := indent
       
  1556                 ] ifFalse:[
       
  1557                     line := line , ' '.
       
  1558                     pos := pos + 1
       
  1559                 ].
       
  1560                 thisName := nextName
       
  1561             ]
       
  1562         ].
       
  1563         aStream nextPutAll:line withTabs
       
  1564     ]
       
  1565 
       
  1566     "Modified: 9.11.1996 / 00:12:06 / cg"
       
  1567     "Created: 22.3.1997 / 14:12:12 / cg"
       
  1568 !
       
  1569 
       
  1570 printNameInHierarchy
       
  1571     ^ self name
       
  1572 !
       
  1573 
       
  1574 privateClassesAt:aClassNameStringOrSymbol
       
  1575     |nmSym|
       
  1576 
       
  1577     nmSym := (self name , '::' , aClassNameStringOrSymbol) asSymbolIfInterned.
       
  1578     nmSym isNil ifTrue:[
       
  1579         "/ no such symbol - there cannot be a corresponding private class
       
  1580         ^ nil
       
  1581     ].
       
  1582 
       
  1583     ^ memory at:nmSym.
       
  1584 !
       
  1585 
       
  1586 sourceCodeManager
       
  1587     ^ SourceCodeManager
       
  1588 !
       
  1589 
       
  1590 syntaxHighlighterClass
       
  1591     ^ Object syntaxHighlighterClass
       
  1592 !
       
  1593 
       
  1594 withAllSuperclassesDo:aBlock
       
  1595     |sc|
       
  1596 
       
  1597     aBlock value:self.
       
  1598     sc := self superclass.
       
  1599     sc notNil ifTrue:[
       
  1600         sc withAllSuperclassesDo:aBlock.
       
  1601     ]
       
  1602 ! !
       
  1603 
       
  1604 !SnapShotImageMemory::ImageClassObject methodsFor:'queries'!
       
  1605 
       
  1606 categories
       
  1607     |newList|
       
  1608 
       
  1609     newList := Set new.
       
  1610     self methodDictionary do:[:aMethod |
       
  1611         |cat|
       
  1612 
       
  1613         cat := aMethod category.
       
  1614         cat isNil ifTrue:[
       
  1615             cat := '* no category *'
       
  1616         ].
       
  1617         newList add:cat
       
  1618     ].
       
  1619     ^ newList
       
  1620 !
       
  1621 
       
  1622 isBytes
       
  1623     ^ (self flags bitAnd:Behavior maskIndexType) == Behavior flagBytes.
       
  1624 !
       
  1625 
       
  1626 isDoubles
       
  1627     ^ (self flags bitAnd:Behavior maskIndexType) == Behavior flagDoubles.
       
  1628 !
       
  1629 
       
  1630 isFloats
       
  1631     ^ (self flags bitAnd:Behavior maskIndexType) == Behavior flagFloats.
       
  1632 !
       
  1633 
       
  1634 isLoaded
       
  1635     ^ self superclass name ~= 'Autoload'
       
  1636 !
       
  1637 
       
  1638 isLongLongs
       
  1639     ^ (self flags bitAnd:Behavior maskIndexType) == Behavior flagLongLongs.
       
  1640 !
       
  1641 
       
  1642 isLongs
       
  1643     ^ (self flags bitAnd:Behavior maskIndexType) == Behavior flagLongs.
       
  1644 !
       
  1645 
       
  1646 isMeta
       
  1647     ^ self size == (Metaclass instSize * memory ptrSize).
       
  1648 "/    ^ classRef classRef name = 'Metaclass'
       
  1649 !
       
  1650 
       
  1651 isPrivate
       
  1652     ^ classRef isPrivateMeta 
       
  1653 !
       
  1654 
       
  1655 isPrivateMeta
       
  1656     ^ classRef name = 'PrivateMetaclass'
       
  1657 !
       
  1658 
       
  1659 isSignedLongLongs
       
  1660     ^ (self flags bitAnd:Behavior maskIndexType) == Behavior flagSignedLongLongs.
       
  1661 !
       
  1662 
       
  1663 isSignedLongs
       
  1664     ^ (self flags bitAnd:Behavior maskIndexType) == Behavior flagSignedLongs.
       
  1665 !
       
  1666 
       
  1667 isSignedWords
       
  1668     ^ (self flags bitAnd:Behavior maskIndexType) == Behavior flagSignedWords.
       
  1669 !
       
  1670 
       
  1671 isVariable
       
  1672     ^ (self flags bitAnd:Behavior maskIndexType) ~= 0.
       
  1673 !
       
  1674 
       
  1675 isWords
       
  1676     ^ (self flags bitAnd:Behavior maskIndexType) == Behavior flagWords.
       
  1677 !
       
  1678 
       
  1679 nameSpace
       
  1680     |env name idx nsName|
       
  1681 
       
  1682 "/    (env := self environment) notNil ifTrue:[^ env].
       
  1683     name := self name.
       
  1684     idx := name lastIndexOf:$:.
       
  1685     idx ~~ 0 ifTrue:[
       
  1686         (name at:idx-1) == $: ifTrue:[
       
  1687             nsName := name copyTo:(idx - 2).
       
  1688             env := Smalltalk at:nsName asSymbol.
       
  1689         ]
       
  1690     ].
       
  1691     ^ env
       
  1692 !
       
  1693 
       
  1694 owningClass
       
  1695     |ownerPtr owner|
       
  1696 
       
  1697     classRef isPrivateMeta ifFalse:[^ nil].
       
  1698     ownerPtr := classRef at:8.
       
  1699     owner := memory fetchClassObjectAt:ownerPtr.
       
  1700     ^ owner
       
  1701 !
       
  1702 
       
  1703 supportsMethodCategories
       
  1704     ^ true
       
  1705 !
       
  1706 
       
  1707 topOwningClass
       
  1708     |owner|
       
  1709 
       
  1710     classRef isPrivateMeta ifTrue:[
       
  1711         owner := self owningClass.
       
  1712         [owner classRef isPrivateMeta] whileTrue:[
       
  1713             owner := owner owningClass
       
  1714         ].
       
  1715         ^ owner
       
  1716     ] ifFalse:[
       
  1717         ^ nil
       
  1718     ].
       
  1719     ^ self halt.
       
  1720 !
       
  1721 
       
  1722 wasAutoloaded
       
  1723     ^ false 
       
  1724 ! !
       
  1725 
       
  1726 !SnapShotImageMemory::ImageByteObject methodsFor:'queries'!
       
  1727 
       
  1728 size
       
  1729     ^ byteSize
   651 ! !
  1730 ! !
   652 
  1731 
   653 !SnapShotImageMemory class methodsFor:'documentation'!
  1732 !SnapShotImageMemory class methodsFor:'documentation'!
   654 
  1733 
   655 version
  1734 version