SnapShotImageMemory.st
changeset 3088 5a5e9b9b5138
parent 2164 3c5fe1d92046
child 3089 994863569542
equal deleted inserted replaced
3087:bbbb798caa45 3088:5a5e9b9b5138
     1 "{ Package: 'stx:libtool2' }"
     1 "{ Package: 'stx:libtool2' }"
     2 
     2 
     3 Object subclass:#SnapShotImageMemory
     3 Object subclass:#SnapShotImageMemory
     4 	instanceVariableNames:'image stream msb ptrSize intSize intTag spaceInfos symbolEntries
     4 	instanceVariableNames:'image stream msb ptrSize intSize intTag spaceInfos symbolEntries
     5 		globalEntries addrToObjectMapping'
     5 		globalEntries addrToObjectMapping fetchINT hdrSize'
     6 	classVariableNames:''
     6 	classVariableNames:''
     7 	poolDictionaries:''
     7 	poolDictionaries:''
     8 	category:'System-Support'
     8 	category:'System-Support'
     9 !
     9 !
    10 
    10 
   134 !
   134 !
   135 
   135 
   136 fetchClassObjectAt:baseAddr
   136 fetchClassObjectAt:baseAddr
   137     |addr classPtr size bits o classRef nInsts|
   137     |addr classPtr size bits o classRef nInsts|
   138 
   138 
   139     (baseAddr bitAnd:3) ~~ 0 ifTrue:[self halt].
   139     (baseAddr bitAnd:ptrSize-1) ~~ 0 ifTrue:[self halt].
   140 
   140 
   141     o := addrToObjectMapping at:(baseAddr bitShift:-2) ifAbsent:nil.
   141     o := addrToObjectMapping at:(baseAddr bitShift:-2) ifAbsent:nil.
   142     o notNil ifTrue:[^ o].
   142     o notNil ifTrue:[^ o].
   143 
   143 
   144     addr := baseAddr.
   144     addr := baseAddr.
   145     classPtr := self fetchPointerAt:addr.
   145     classPtr := self fetchPointerAt:addr.
   146     addr := addr + ptrSize.
   146     addr := addr + ptrSize.
   147     size := self fetchUnboxedIntegerAt:addr.
   147     size := self fetchUnboxedInteger4At:addr.
   148     addr := addr + ptrSize.
   148     addr := addr + 4.
   149     bits := self fetchUnboxedIntegerAt:addr.
   149     bits := self fetchUnboxedInteger4At:addr.
   150     addr := addr + ptrSize.
   150     addr := addr + 4.
   151 
   151 
   152     nInsts := (size - (intSize * 3 "headerSize")) // intSize.
   152     nInsts := (size - hdrSize) // intSize.
   153     o := ImageClassObject new:nInsts.
   153     o := ImageClassObject new:nInsts.
   154     o memory:self.
   154     o memory:self.
   155     o address:baseAddr.
   155     o address:baseAddr.
   156     addrToObjectMapping at:(baseAddr bitShift:-2) put:o.
   156     addrToObjectMapping at:(baseAddr bitShift:-2) put:o.
   157 
   157 
   158     (self class isPointerOOP:classPtr) ifFalse:[
   158     (self class isPointerOOP:classPtr) ifFalse:[
   159         self halt
   159         self halt
   160     ].
   160     ].
   161 
   161 
   162 size > 8000 ifTrue:[self halt].
   162     "/ size > 8000 ifTrue:[self halt].
   163     o byteSize:size.
   163     o byteSize:size.
   164     o bits:bits.
   164     o bits:bits.
   165 
   165 
   166     1 to:nInsts do:[:idx |
   166     1 to:nInsts do:[:idx |
   167         o at:idx put:(self fetchUnboxedIntegerAt:addr).
   167         o at:idx put:(fetchINT value).
   168 "/        o at:idx put:(self fetchObjectAt:(self fetchUnboxedIntegerAt:addr)).
   168 "/        o at:idx put:(self fetchObjectAt:(self fetchUnboxedIntegerAt:addr)).
   169         addr := addr + ptrSize.
   169         addr := addr + ptrSize.
   170     ].
   170     ].
   171 
   171 
   172     classRef := self fetchClassObjectAt:classPtr.
   172     classRef := self fetchClassObjectAt:classPtr.
   174 
   174 
   175     ^ o
   175     ^ o
   176 !
   176 !
   177 
   177 
   178 fetchObjectAt:baseAddr
   178 fetchObjectAt:baseAddr
   179     |addr classPtr classRef size bits o nBytes nInsts flags indexTypeFlags imgAddr
   179     |addr classPtr classRef size bits o nBytes nInsts flags indexTypeFlags imgAddr|
   180      |
       
   181 
   180 
   182     baseAddr == 0 ifTrue:[^ nil].
   181     baseAddr == 0 ifTrue:[^ nil].
   183     (baseAddr bitAnd:1) == 1 ifTrue:[
   182     (baseAddr bitAnd:1) == 1 ifTrue:[
   184         (baseAddr bitTest:16r80000000) ifTrue:[
   183         "/ sign extent integer
   185             ^ (baseAddr - 16r100000000) bitShift32:-1
   184         ptrSize == 8 ifTrue:[
   186         ] ifFalse:[   
   185             (baseAddr bitTest:16r8000000000000000) ifTrue:[
       
   186                 ^ (baseAddr - 16r10000000000000000) bitShift:-1
       
   187             ].
       
   188             ^ baseAddr bitShift:-1
       
   189         ] ifFalse:[
       
   190             (baseAddr bitTest:16r80000000) ifTrue:[
       
   191                 ^ (baseAddr - 16r100000000) bitShift32:-1
       
   192             ].
   187             ^ baseAddr bitShift32:-1
   193             ^ baseAddr bitShift32:-1
   188         ]
   194         ].
   189     ].
   195     ].
   190     (baseAddr bitAnd:3) ~~ 0 ifTrue:[self halt].
   196     (baseAddr bitAnd:ptrSize-1) ~~ 0 ifTrue:[self halt].
   191 
   197 
   192     o := addrToObjectMapping at:(baseAddr bitShift:-2) ifAbsent:nil.
   198     o := addrToObjectMapping at:(baseAddr bitShift:-2) ifAbsent:nil.
   193     o notNil ifTrue:[^ o].
   199     o notNil ifTrue:[^ o].
   194 
   200 
   195     addr := baseAddr.
   201     addr := baseAddr.
   196     classPtr := self fetchPointerAt:addr.
   202     classPtr := self fetchPointerAt:addr.
   197     addr := addr + ptrSize.
   203     addr := addr + ptrSize.
   198     size := self fetchUnboxedIntegerAt:addr.
   204     size := self fetchUnboxedInteger4At:addr.
   199     addr := addr + ptrSize.
   205     addr := addr + 4.
   200     bits := self fetchUnboxedIntegerAt:addr.
   206     bits := self fetchUnboxedInteger4At:addr.
   201     addr := addr + ptrSize.
   207     addr := addr + 4.
   202 
   208 
   203     (self class isPointerOOP:classPtr) ifFalse:[
   209     (self class isPointerOOP:classPtr) ifFalse:[
   204         self halt
   210         self halt
   205     ].
   211     ].
   206 
   212 
   207     classRef := self fetchClassObjectAt:classPtr.
   213     classRef := self fetchClassObjectAt:classPtr.
       
   214 
       
   215     imgAddr := self imageAddressOf:addr.
       
   216     stream position:imgAddr.
   208 
   217 
   209     flags := classRef flags.
   218     flags := classRef flags.
   210     indexTypeFlags := flags bitAnd:Behavior maskIndexType.
   219     indexTypeFlags := flags bitAnd:Behavior maskIndexType.
   211     (indexTypeFlags = Behavior flagBytes) ifTrue:[ 
   220     (indexTypeFlags = Behavior flagBytes) ifTrue:[ 
   212         nBytes := (size - (intSize * 3)).
   221         nBytes := (size - hdrSize).
   213         o := ImageByteObject new:nBytes.
   222         o := ImageByteObject new:nBytes.
   214         o memory:self.
   223         o memory:self.
   215         o address:baseAddr.
   224         o address:baseAddr.
   216         o classRef:classRef.
   225         o classRef:classRef.
   217 "/ size > 8000 ifTrue:[self halt].
   226         "/ size > 8000 ifTrue:[self halt].
   218         o byteSize:size.
   227         o byteSize:size.
   219         o bits:bits.
   228         o bits:bits.
   220         addrToObjectMapping at:(baseAddr bitShift:-2) put:o.
   229         addrToObjectMapping at:(baseAddr bitShift:-2) put:o.
   221 
       
   222         imgAddr := self imageAddressOf:addr.
       
   223         stream position:imgAddr.
       
   224 
   230 
   225         1 to:nBytes do:[:idx |
   231         1 to:nBytes do:[:idx |
   226             o at:idx put:(stream next).
   232             o at:idx put:(stream next).
   227             addr := addr + 1.
   233             addr := addr + 1.
   228         ].
   234         ].
   238                     self halt 
   244                     self halt 
   239                 ]
   245                 ]
   240             ].
   246             ].
   241         ].
   247         ].
   242 
   248 
   243         nInsts := (size - (intSize * 3)) // intSize.
   249         nInsts := (size - hdrSize) // intSize.
   244         (flags bitTest:Behavior flagBehavior)
   250         (flags bitTest:Behavior flagBehavior)
   245         "/ classRef isImageBehavior 
   251         "/ classRef isImageBehavior 
   246         ifTrue:[
   252         ifTrue:[
   247             o := ImageClassObject new:nInsts.
   253             o := ImageClassObject new:nInsts.
   248         ] ifFalse:[
   254         ] ifFalse:[
   259         o byteSize:size.
   265         o byteSize:size.
   260         o bits:bits.
   266         o bits:bits.
   261         addrToObjectMapping at:(baseAddr bitShift:-2) put:o.
   267         addrToObjectMapping at:(baseAddr bitShift:-2) put:o.
   262 
   268 
   263         1 to:nInsts do:[:idx |
   269         1 to:nInsts do:[:idx |
   264             o at:idx put:(self fetchUnboxedIntegerAt:addr).
   270             o at:idx put:(fetchINT value).
   265 "/            o at:idx put:(self fetchObjectAt:(self fetchUnboxedIntegerAt:addr)).
   271 "/            o at:idx put:(self fetchObjectAt:(self fetchUnboxedIntegerAt:addr)).
   266             addr := addr + ptrSize.
   272             addr := addr + ptrSize.
   267         ]
   273         ]
   268     ].
   274     ].
   269     ^ o
   275     ^ o
   271 
   277 
   272 fetchPointerAt:addr
   278 fetchPointerAt:addr
   273     ^ self fetchUnboxedIntegerAt:addr
   279     ^ self fetchUnboxedIntegerAt:addr
   274 !
   280 !
   275 
   281 
   276 fetchUnboxedIntegerAt:addr
   282 fetchUnboxedInteger4At:addr
   277     |ptr imgAddr|
   283     |ptr imgAddr|
   278 
   284 
   279     (addr bitAnd:3) ~~ 0 ifTrue:[self halt].
   285     (addr bitAnd:(4-1)) ~~ 0 ifTrue:[self halt].
   280 
   286 
   281     imgAddr := self imageAddressOf:addr.
   287     imgAddr := self imageAddressOf:addr.
   282     stream position:imgAddr.
   288     stream position:imgAddr.
   283     ptr := stream nextUnsignedLongMSB:msb.
   289     ptr := stream nextUnsignedLongMSB:msb.
       
   290     ^ ptr
       
   291 !
       
   292 
       
   293 fetchUnboxedIntegerAt:addr
       
   294     |ptr imgAddr|
       
   295 
       
   296     (addr bitAnd:(ptrSize-1)) ~~ 0 ifTrue:[self halt].
       
   297 
       
   298     imgAddr := self imageAddressOf:addr.
       
   299     stream position:imgAddr.
       
   300     ptr := fetchINT value.
   284     ^ ptr
   301     ^ ptr
   285 !
   302 !
   286 
   303 
   287 imageAddressOf:addr
   304 imageAddressOf:addr
   288     spaceInfos do:[:eachSpace |
   305     spaceInfos do:[:eachSpace |
   316 fetchByteArrayFor:aByteArrayRef
   333 fetchByteArrayFor:aByteArrayRef
   317     |nBytes|
   334     |nBytes|
   318 
   335 
   319     (aByteArrayRef isImageBytes) ifFalse:[self halt].
   336     (aByteArrayRef isImageBytes) ifFalse:[self halt].
   320 
   337 
   321     nBytes := aByteArrayRef byteSize - (intSize * 3).
   338     nBytes := aByteArrayRef byteSize - hdrSize.
   322     ^ ((ByteArray new:nBytes) replaceFrom:1 to:nBytes-1 with:aByteArrayRef startingAt:1).
   339     ^ ((ByteArray new:nBytes) replaceFrom:1 to:nBytes-1 with:aByteArrayRef startingAt:1).
   323 !
   340 !
   324 
   341 
   325 fetchStringFor:aStringRef
   342 fetchStringFor:aStringRef
   326     |nBytes|
   343     |nBytes|
   327 
   344 
   328     (aStringRef isImageBytes) ifFalse:[self halt].
   345     (aStringRef isImageBytes) ifFalse:[self halt].
   329 
   346 
   330     nBytes := aStringRef byteSize - (intSize * 3).
   347     nBytes := aStringRef byteSize - hdrSize.
   331     ^ ((ByteArray new:nBytes-1) replaceFrom:1 to:nBytes-1 with:aStringRef startingAt:1) asString.
   348     ^ ((ByteArray new:nBytes-1) 
       
   349             replaceFrom:1 to:nBytes-1 with:aStringRef startingAt:1) asString.
   332 !
   350 !
   333 
   351 
   334 for:aFilename
   352 for:aFilename
   335     stream := aFilename asFilename readStream binary.
   353     stream := aFilename asFilename readStream binary.
   336     addrToObjectMapping := IdentityDictionary new.
   354     addrToObjectMapping := IdentityDictionary new.
   341 
   359 
   342 printStringOfClass:aClassRef
   360 printStringOfClass:aClassRef
   343     |nameSlot|
   361     |nameSlot|
   344 
   362 
   345     (aClassRef isImageBehavior) ifFalse:[self halt].
   363     (aClassRef isImageBehavior) ifFalse:[self halt].
   346     ((aClassRef byteSize // intSize) - 3) < Class instSize ifTrue:[self halt.].
   364     ((aClassRef byteSize - hdrSize) // intSize) < Class instSize ifTrue:[self halt.].
   347 
   365 
   348     nameSlot := aClassRef nameSlot.
   366     nameSlot := aClassRef nameSlot.
   349     nameSlot isInteger ifTrue:[
   367     nameSlot isInteger ifTrue:[
   350         nameSlot := self fetchObjectAt:nameSlot
   368         nameSlot := self fetchObjectAt:nameSlot
   351     ].
   369     ].
   373     (aStringRef isString) ifFalse:[self halt].
   391     (aStringRef isString) ifFalse:[self halt].
   374     ^ self fetchStringFor:aStringRef.
   392     ^ self fetchStringFor:aStringRef.
   375 !
   393 !
   376 
   394 
   377 printStringOfSymbol:aSymbolRef
   395 printStringOfSymbol:aSymbolRef
   378     |nBytes|
       
   379 
       
   380     (aSymbolRef isImageSymbol) ifFalse:[self halt].
   396     (aSymbolRef isImageSymbol) ifFalse:[self halt].
   381     ^ self fetchStringFor:aSymbolRef.
   397     ^ self fetchStringFor:aSymbolRef.
   382 "/    nBytes := aSymbolRef size - (intSize * 3).
       
   383 "/    ^ ((ByteArray new:nBytes-1) replaceFrom:1 to:nBytes-1 with:aSymbolRef startingAt:1) asString.
       
   384 !
   398 !
   385 
   399 
   386 readGlobalEntries
   400 readGlobalEntries
   387         |refPointer theSymbolPtr theSymbolRef theValuePtr theValueRef pos|
   401         |refPointer theSymbolPtr theSymbolRef theValuePtr theValueRef pos|
   388 
   402 
   389         globalEntries := OrderedCollection new.
   403         globalEntries := OrderedCollection new.
   390         [
   404         [
   391             refPointer := stream nextUnsignedLongMSB:msb.
   405             refPointer := fetchINT value.
   392             theSymbolPtr := stream nextUnsignedLongMSB:msb.
   406             theSymbolPtr := fetchINT value.
   393             theValuePtr := stream nextUnsignedLongMSB:msb.
   407             theValuePtr := fetchINT value.
   394             theSymbolPtr ~~ 0
   408             theSymbolPtr ~~ 0
   395         ] whileTrue:[
   409         ] whileTrue:[
   396             globalEntries add:(theSymbolPtr -> theValuePtr).
   410             globalEntries add:(theSymbolPtr -> theValuePtr).
   397         ].
   411         ].
   398         globalEntries := globalEntries asArray.
   412         globalEntries := globalEntries asArray.
   417         stream position:pos.
   431         stream position:pos.
   418 !
   432 !
   419 
   433 
   420 readHeader
   434 readHeader
   421         "
   435         "
   422          (self for:'stmeas.img') readHeader
   436          (self for:'st.img') readHeader
   423          (self for:'crash.img') readHeader
   437          (self for:'crash.img') readHeader
   424         "
   438         "
   425 
   439 
   426         |order magic version timeStamp snapID last_util_addr hiText_addr flags 
   440         |order magic version timeStamp snapID last_util_addr hiText_addr flags 
   427          lowData hiData charSlots charTableSlots fixMemStart fixMemEnd 
   441          lowData hiData charSlots charTableSlots fixMemStart fixMemEnd 
   447         ].
   461         ].
   448         version := stream nextUnsignedLongMSB:msb.        
   462         version := stream nextUnsignedLongMSB:msb.        
   449         timeStamp := stream nextUnsignedLongMSB:msb.        
   463         timeStamp := stream nextUnsignedLongMSB:msb.        
   450         ptrSize := stream nextByte.        
   464         ptrSize := stream nextByte.        
   451         ptrSize ~~ 4 ifTrue:[
   465         ptrSize ~~ 4 ifTrue:[
   452             self error:'unhandled ptr format'
   466             ptrSize ~~ 8 ifTrue:[
       
   467                 self error:'unhandled ptr format'
       
   468             ].
   453         ].
   469         ].
   454         stream next:7.    "/ filler    
   470         stream next:7.    "/ filler    
   455         intSize := stream nextUnsignedLongMSB:msb.        
   471         intSize := stream nextUnsignedLongMSB:msb.        
   456         intSize == 9 ifTrue:[
   472         intSize == 9 "encoded as SmallInteger; i.e. with tag" ifTrue:[
   457             intSize := 4.
   473             intSize := 4.
   458             intTag := 1.
   474             intTag := 1.
   459         ] ifFalse:[
   475         ] ifFalse:[
   460             self error:'unhandled int format'
   476             intSize == 17 "encoded as SmallInteger; i.e. with tag" ifTrue:[
   461         ].
   477                 intSize := 8.
   462         
   478                 intTag := 1.
       
   479             ] ifFalse:[
       
   480                 self error:'unhandled int format'
       
   481             ].
       
   482         ].
       
   483         hdrSize := ptrSize + 4 + 4.
       
   484 
       
   485         intSize == 4 ifTrue:[
       
   486             fetchINT := [stream nextUnsignedLongMSB:msb] 
       
   487         ] ifFalse:[
       
   488             fetchINT := [stream nextUnsignedHyperMSB:msb]
       
   489         ].
       
   490 
   463         snapID := stream nextUnsignedLongMSB:msb.        
   491         snapID := stream nextUnsignedLongMSB:msb.        
   464         last_util_addr := stream next:intSize.        
   492         intSize == 8 ifTrue:[
   465         hiText_addr := stream next:intSize.        
   493             "/ sigh - align for 8byte
   466         flags := stream next:intSize.        
   494             stream next:4
   467         stream next:8.    "/ info, debug & filler    
   495         ].
   468 
   496         last_util_addr := fetchINT value.        
   469         lowData := stream nextUnsignedLongMSB:msb.
   497         hiText_addr := fetchINT value.
   470         hiData := stream nextUnsignedLongMSB:msb.
   498         flags := fetchINT value.        
   471 
   499         "infoPrinting :=" stream next.
   472         charSlots := stream nextUnsignedLongMSB:msb.
   500         "debugPrinting :=" stream next.
   473         charTableSlots := stream nextUnsignedLongMSB:msb.
   501         stream next:6.    "/ filler    
       
   502 
       
   503         lowData := fetchINT value.
       
   504         hiData := fetchINT value.
       
   505 
       
   506         charSlots := fetchINT value.
       
   507         charTableSlots := fetchINT value.
   474 
   508 
   475         version >= 8 ifTrue:[
   509         version >= 8 ifTrue:[
   476             fixMemStart := stream nextUnsignedLongMSB:msb.
   510             fixMemStart := fetchINT value.
   477             fixMemEnd := stream nextUnsignedLongMSB:msb.
   511             fixMemEnd := fetchINT value.
   478             symMemStart := stream nextUnsignedLongMSB:msb.
   512             symMemStart := fetchINT value.
   479             symMemEnd := stream nextUnsignedLongMSB:msb.
   513             symMemEnd := fetchINT value.
   480             vmDataAddr := stream nextUnsignedLongMSB:msb.
   514             vmDataAddr := fetchINT value.
   481         ].
   515         ].
   482         stream next:(128 * intSize).    "/ skip sharedMethodCode ptrs
   516         stream next:(128 * intSize).    "/ skip sharedMethodCode ptrs
   483         stream next:(128 * intSize).    "/ skip sharedBlockCode ptrs
   517         stream next:(128 * intSize).    "/ skip sharedBlockCode ptrs
   484 
   518 
   485         nContexts := stream nextUnsignedLongMSB:msb.
   519         nContexts := fetchINT value.
   486         contextSpace := stream nextUnsignedLongMSB:msb.
   520         contextSpace := fetchINT value.
   487         nRegistered := stream nextUnsignedLongMSB:msb.
   521         nRegistered := fetchINT value.
   488 
   522 
   489         version >= 8 ifTrue:[
   523         version >= 8 ifTrue:[
   490             version >= 9 ifTrue:[
   524             version >= 9 ifTrue:[
   491                 symbolsSeqNr := stream nextUnsignedLongMSB:msb.
   525                 symbolsSeqNr := fetchINT value.
   492                 version >= 10 ifTrue:[
   526                 version >= 10 ifTrue:[
   493                     numCharSlots := stream nextUnsignedLongMSB:msb.
   527                     numCharSlots := fetchINT value.
   494                     stream next:(intSize * 30).
   528                     stream next:(intSize * 30).
   495                 ] ifFalse:[
   529                 ] ifFalse:[
   496                     stream next:(intSize * 31).
   530                     stream next:(intSize * 31).
   497                 ].
   531                 ].
   498             ] ifFalse:[
   532             ] ifFalse:[
   499                 stream next:(intSize * 32).
   533                 stream next:(intSize * 32).
   500             ]
   534             ]
   501         ].
   535         ].
   502 
   536 
   503         nSpaces := stream nextUnsignedLongMSB:msb.
   537         nSpaces := fetchINT value.
   504         spaceInfos := (1 to:nSpaces) collect:[:idx | SpaceInfo new].
   538         spaceInfos := (1 to:nSpaces) collect:[:idx | SpaceInfo new].
   505         
   539         
   506         1 to:nSpaces do:[:i |
   540         1 to:nSpaces do:[:i |
   507             (spaceInfos at:i) flags:(stream nextUnsignedLongMSB:msb).
   541             (spaceInfos at:i) flags:(fetchINT value).
   508         ].
   542         ].
   509         nSpaces+1 to:32 do:[:i | stream nextUnsignedLongMSB:msb].
   543         nSpaces+1 to:32 do:[:i | fetchINT value].
   510 
   544 
   511         1 to:nSpaces do:[:i |
   545         1 to:nSpaces do:[:i |
   512             (spaceInfos at:i) start:(stream nextUnsignedLongMSB:msb).
   546             (spaceInfos at:i) start:(fetchINT value).
   513         ].
   547         ].
   514         nSpaces+1 to:32 do:[:i | stream nextUnsignedLongMSB:msb].
   548         nSpaces+1 to:32 do:[:i | fetchINT value].
   515 
   549 
   516         1 to:nSpaces do:[:i |
   550         1 to:nSpaces do:[:i |
   517             (spaceInfos at:i) size:(stream nextUnsignedLongMSB:msb).
   551             (spaceInfos at:i) size:(fetchINT value).
   518         ].
   552         ].
   519         nSpaces+1 to:32 do:[:i | stream nextUnsignedLongMSB:msb].
   553         nSpaces+1 to:32 do:[:i | fetchINT value].
   520         version >= 8 ifTrue:[
   554         version >= 8 ifTrue:[
   521             stream reset.
   555             stream reset.
   522             stream skip:4096.
   556             stream skip:4096.
   523         ].
   557         ].
   524 
   558 
   659             |className flags moduleTimestamp signature nMethods nBlocks oldLitRefs nLitRefs
   693             |className flags moduleTimestamp signature nMethods nBlocks oldLitRefs nLitRefs
   660              oldConstTable nConsts|
   694              oldConstTable nConsts|
   661 
   695 
   662             className := (stream next:classNameSize) asString.
   696             className := (stream next:classNameSize) asString.
   663             stream next. "/ 0-byte
   697             stream next. "/ 0-byte
   664             flags := stream nextUnsignedLongMSB:msb.
   698             flags := fetchINT value.
   665             moduleTimestamp := stream nextUnsignedLongMSB:msb.   
   699             moduleTimestamp := fetchINT value.   
   666             signature := stream nextUnsignedLongMSB:msb.   
   700             signature := fetchINT value.   
   667             nMethods := stream nextUnsignedLongMSB:msb.   
   701             nMethods := stream nextUnsignedLongMSB:msb.   
   668             nMethods timesRepeat:[ stream nextUnsignedLongMSB:msb ].
   702             nMethods timesRepeat:[ fetchINT value ].
   669             nBlocks := stream nextUnsignedLongMSB:msb.   
   703             nBlocks := stream nextUnsignedLongMSB:msb.   
   670             nBlocks timesRepeat:[ stream nextUnsignedLongMSB:msb ].
   704             nBlocks timesRepeat:[ fetchINT value ].
   671             oldLitRefs := stream nextUnsignedLongMSB:msb.  
   705 
       
   706             oldLitRefs := fetchINT value.  
   672             nLitRefs := stream nextUnsignedLongMSB:msb.
   707             nLitRefs := stream nextUnsignedLongMSB:msb.
   673             nLitRefs timesRepeat:[ stream nextUnsignedLongMSB:msb ].
   708             nLitRefs timesRepeat:[ fetchINT value ].
   674             stream nextUnsignedLongMSB:msb. "/ 0-litRef
   709             fetchINT value. "/ 0-litRef
   675             oldConstTable := stream nextUnsignedLongMSB:msb.  
   710             oldConstTable := fetchINT value.  
   676             nConsts := stream nextLongMSB:msb.
   711             nConsts := stream nextLongMSB:msb.
   677             nConsts > 0 ifTrue:[
   712             nConsts > 0 ifTrue:[
   678                 nConsts timesRepeat:[ stream nextUnsignedLongMSB:msb ].
   713                 nConsts timesRepeat:[ fetchINT value ].
   679             ]
   714             ].
   680             "/ Transcript showCR:className.
   715 "/            Transcript show:className; 
       
   716 "/                    show:' nconsts:'; show:nConsts; 
       
   717 "/                    show:' nlits:'; show:nLitRefs;
       
   718 "/                    show:' nMethods:'; show:nMethods;
       
   719 "/                    show:' nBlocks:'; showCR:nBlocks.
   681         ].
   720         ].
   682 !
   721 !
   683 
   722 
   684 readSymbolEntries
   723 readSymbolEntries
   685         |refPointer theSymbolPtr theSymbolRef pos|
   724         |refPointer theSymbolPtr theSymbolRef pos|
   686 
   725 
   687         symbolEntries := OrderedCollection new.
   726         symbolEntries := OrderedCollection new.
   688 
   727 
   689         [
   728         [
   690             refPointer := stream nextUnsignedLongMSB:msb.
   729             refPointer := fetchINT value.
   691             theSymbolPtr := stream nextUnsignedLongMSB:msb.
   730             theSymbolPtr := fetchINT value.
   692             theSymbolPtr ~~ 0
   731             theSymbolPtr ~~ 0
   693         ] whileTrue:[
   732         ] whileTrue:[
   694             symbolEntries add:theSymbolPtr.
   733             symbolEntries add:theSymbolPtr.
   695         ].
   734         ].
   696         symbolEntries := symbolEntries asArray.
   735         symbolEntries := symbolEntries asArray.
   697 
   736 
   698         pos := stream position.
   737         pos := stream position.
   699         symbolEntries := symbolEntries collect:[:theSymbolPtr |
   738         1 to:symbolEntries size do:[:i |
       
   739             |theSymbolPtr|
       
   740 
       
   741             "/ an inlined collect, to avoid allocating big array twice.
       
   742             theSymbolPtr := symbolEntries at:i.
   700             theSymbolRef := self fetchObjectAt:theSymbolPtr.
   743             theSymbolRef := self fetchObjectAt:theSymbolPtr.
   701             theSymbolRef isImageSymbol ifFalse:[
   744             theSymbolRef isImageSymbol ifFalse:[
   702                 self halt
   745                 self halt
   703             ].
   746             ].
       
   747             symbolEntries at:i put:theSymbolRef.
   704         ].        
   748         ].        
   705         stream position:pos
   749         stream position:pos
   706 !
   750 !
   707 
   751 
   708 readUGlobalEntries
   752 readUGlobalEntries
   709         |refPointer theValue|
   753         |refPointer theValue|
   710 
   754 
   711         [
   755         [
   712             refPointer := stream nextUnsignedLongMSB:msb.
   756             refPointer := fetchINT value.
   713             theValue := stream nextUnsignedLongMSB:msb.
   757             theValue := fetchINT value.
   714             refPointer ~~ 0
   758             refPointer ~~ 0
   715         ] whileTrue
   759         ] whileTrue
       
   760 ! !
       
   761 
       
   762 !SnapShotImageMemory methodsFor:'queries'!
       
   763 
       
   764 metaClassByteSize
       
   765     ^ Metaclass instSize * ptrSize + hdrSize
       
   766 !
       
   767 
       
   768 privateMetaClassByteSize
       
   769     ^ PrivateMetaclass instSize * ptrSize + hdrSize
   716 ! !
   770 ! !
   717 
   771 
   718 !SnapShotImageMemory::ImageHeader methodsFor:'accessing'!
   772 !SnapShotImageMemory::ImageHeader methodsFor:'accessing'!
   719 
   773 
   720 address:something
   774 address:something
  1569         comment := memory fetchStringFor:commentRef.
  1623         comment := memory fetchStringFor:commentRef.
  1570     ].
  1624     ].
  1571     ^ comment
  1625     ^ comment
  1572 !
  1626 !
  1573 
  1627 
       
  1628 commentOrDocumentationString
       
  1629     "the classes documentation-method's comment, its plain
       
  1630      comment or nil"
       
  1631 
       
  1632     |cls m s|
       
  1633 
       
  1634     cls := self theNonMetaclass.
       
  1635     m := cls theMetaclass compiledMethodAt:#documentation.
       
  1636     m notNil ifTrue:[
       
  1637         "/ try documentation method's comment
       
  1638         s := m comment.
       
  1639     ] ifFalse:[
       
  1640         "try classes comment"
       
  1641         s := cls comment.
       
  1642         s isString ifTrue:[
       
  1643             s isEmpty ifTrue:[
       
  1644                 s := nil
       
  1645             ] ifFalse:[
       
  1646                 (s includes:$") ifTrue:[
       
  1647                     s := s copyReplaceAll:$" with:$'.
       
  1648                 ].
       
  1649                 s size > 80 ifTrue:[
       
  1650                     s := s asCollectionOfSubstringsSeparatedBy:$..
       
  1651                     s := s asStringCollection.
       
  1652                     s := s collect:[:each | (each startsWith:Character space) ifTrue:[
       
  1653                                                 each copyFrom:2
       
  1654                                             ] ifFalse:[
       
  1655                                                 each
       
  1656                                             ]
       
  1657                                    ].
       
  1658                     s := s asStringWith:('.' , Character cr).
       
  1659                 ].
       
  1660             ]
       
  1661         ] ifFalse:[
       
  1662             "/ class redefines comment ?
       
  1663             s := nil
       
  1664         ].
       
  1665     ].
       
  1666     s isEmptyOrNil ifTrue:[^ s].
       
  1667     ^ s withTabsExpanded
       
  1668 
       
  1669     "
       
  1670      Array commentOrDocumentationString
       
  1671     "
       
  1672 !
       
  1673 
  1574 commentSlot
  1674 commentSlot
  1575     ^ self at:(Class instVarOffsetOf:'comment')
  1675     ^ self at:(Class instVarOffsetOf:'comment')
  1576 !
  1676 !
  1577 
  1677 
  1578 flags
  1678 flags
  1579     |flags amount|
  1679     |flags|
  1580 
  1680 
  1581     cachedFlags isNil ifTrue:[
  1681     cachedFlags isNil ifTrue:[
  1582         flags := self flagsSlot.
  1682         flags := self flagsSlot.
  1583 
  1683 
  1584         (SnapShotImageMemory isSmallIntegerOOP:flags) ifFalse:[
  1684         (SnapShotImageMemory isSmallIntegerOOP:flags) ifFalse:[
  1585             self halt
  1685             self halt
  1586         ].
  1686         ].
  1587         amount := -1.
  1687         cachedFlags := flags bitShift:-1.
  1588         cachedFlags := flags bitShift:amount.
       
  1589     ].
  1688     ].
  1590     ^ cachedFlags
  1689     ^ cachedFlags
  1591 !
  1690 !
  1592 
  1691 
  1593 flagsSlot
  1692 flagsSlot
  4018 
  4117 
  4019 isMeta
  4118 isMeta
  4020     |clsName|
  4119     |clsName|
  4021 
  4120 
  4022     thisContext isRecursive ifTrue:[^ false].
  4121     thisContext isRecursive ifTrue:[^ false].
  4023     byteSize = (Metaclass instSize * 4 + 12) ifFalse:[^ false].
  4122     byteSize = memory metaClassByteSize ifFalse:[^ false].
  4024 
  4123 
  4025     clsName := classRef name.
  4124     clsName := classRef name.
  4026     ^ clsName = 'Metaclass' or:[clsName = 'PrivateMetaclass'].
  4125     ^ clsName = 'Metaclass' or:[clsName = 'PrivateMetaclass'].
  4027 
  4126 
  4028 "/self halt.
  4127 "/self halt.
  4043     ^ classRef isPrivateMeta 
  4142     ^ classRef isPrivateMeta 
  4044 !
  4143 !
  4045 
  4144 
  4046 isPrivateMeta
  4145 isPrivateMeta
  4047     thisContext isRecursive ifTrue:[^ false].
  4146     thisContext isRecursive ifTrue:[^ false].
  4048     byteSize = (PrivateMetaclass instSize * 4 + 12) ifFalse:[^ false].
  4147     byteSize = memory privateMetaClassByteSize ifFalse:[^ false].
  4049     ^ classRef name = 'PrivateMetaclass'
  4148     ^ classRef name = 'PrivateMetaclass'
  4050 !
  4149 !
  4051 
  4150 
  4052 isSignedLongLongs
  4151 isSignedLongLongs
  4053     ^ (self flags bitAnd:Behavior maskIndexType) == Behavior flagSignedLongLongs.
  4152     ^ (self flags bitAnd:Behavior maskIndexType) == Behavior flagSignedLongLongs.
  4204 !SnapShotImageMemory class methodsFor:'documentation'!
  4303 !SnapShotImageMemory class methodsFor:'documentation'!
  4205 
  4304 
  4206 version
  4305 version
  4207     ^ '$Header$'
  4306     ^ '$Header$'
  4208 ! !
  4307 ! !
       
  4308