SnapShotImageMemory.st
changeset 1864 41ebace0f00a
parent 1792 9848e561e597
child 1865 ed59f67b9fee
equal deleted inserted replaced
1863:f9a8e3c20143 1864:41ebace0f00a
     7 	poolDictionaries:''
     7 	poolDictionaries:''
     8 	category:'System-Support'
     8 	category:'System-Support'
     9 !
     9 !
    10 
    10 
    11 Object subclass:#ImageHeader
    11 Object subclass:#ImageHeader
    12 	instanceVariableNames:'memory classRef bits byteSize'
    12 	instanceVariableNames:'memory address classRef bits byteSize'
    13 	classVariableNames:''
    13 	classVariableNames:''
    14 	poolDictionaries:''
    14 	poolDictionaries:''
    15 	privateIn:SnapShotImageMemory
    15 	privateIn:SnapShotImageMemory
    16 !
    16 !
    17 
    17 
    56 "
    56 "
    57     I represent the memory as contained in a snapshot image.
    57     I represent the memory as contained in a snapshot image.
    58 
    58 
    59     I am not used directly; instead, via the SystemBrowsers entry:
    59     I am not used directly; instead, via the SystemBrowsers entry:
    60         SystemBrowser openOnSnapShotImage:'/export/home/cg/work/stx/projects/smalltalk/st.img'
    60         SystemBrowser openOnSnapShotImage:'/export/home/cg/work/stx/projects/smalltalk/st.img'
       
    61         SystemBrowser openOnSnapShotImage:'crash.img'
    61 
    62 
    62     [author:]
    63     [author:]
    63         Claus Gittinger
    64         Claus Gittinger
    64 
    65 
    65 "
    66 "
   135 fetchClassObjectAt:baseAddr
   136 fetchClassObjectAt:baseAddr
   136     |addr classPtr size bits o classRef nInsts|
   137     |addr classPtr size bits o classRef nInsts|
   137 
   138 
   138     (baseAddr bitAnd:3) ~~ 0 ifTrue:[self halt].
   139     (baseAddr bitAnd:3) ~~ 0 ifTrue:[self halt].
   139 
   140 
   140     o := addrToObjectMapping at:baseAddr ifAbsent:nil.
   141     o := addrToObjectMapping at:(baseAddr bitShift:-2) ifAbsent:nil.
   141     o notNil ifTrue:[^ o].
   142     o notNil ifTrue:[^ o].
   142 
   143 
   143     addr := baseAddr.
   144     addr := baseAddr.
   144     classPtr := self fetchPointerAt:addr.
   145     classPtr := self fetchPointerAt:addr.
   145     addr := addr + ptrSize.
   146     addr := addr + ptrSize.
   146     size := self fetchUnboxedIntegerAt:addr.
   147     size := self fetchUnboxedIntegerAt:addr.
   147     addr := addr + ptrSize.
   148     addr := addr + ptrSize.
   148     bits := self fetchUnboxedIntegerAt:addr.
   149     bits := self fetchUnboxedIntegerAt:addr.
   149     addr := addr + ptrSize.
   150     addr := addr + ptrSize.
   150 
   151 
   151     nInsts := (size - (intSize *3)) // intSize.
   152     nInsts := (size - (intSize * 3 "headerSize")) // intSize.
   152     o := ImageClassObject new:nInsts.
   153     o := ImageClassObject new:nInsts.
   153     addrToObjectMapping at:baseAddr put:o.
   154     o memory:self.
       
   155     o address:baseAddr.
       
   156     addrToObjectMapping at:(baseAddr bitShift:-2) put:o.
   154 
   157 
   155     (self class isPointerOOP:classPtr) ifFalse:[
   158     (self class isPointerOOP:classPtr) ifFalse:[
   156         self halt
   159         self halt
   157     ].
   160     ].
   158 
   161 
   159     classRef := self fetchClassObjectAt:classPtr.
       
   160 
       
   161     o classRef:classRef.
       
   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:(self fetchUnboxedIntegerAt:addr).
   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     o memory:self.
   171 
       
   172     classRef := self fetchClassObjectAt:classPtr.
       
   173     o classRef:classRef.
       
   174 
   172     ^ o
   175     ^ o
   173 !
   176 !
   174 
   177 
   175 fetchObjectAt:baseAddr
   178 fetchObjectAt:baseAddr
   176     |addr classPtr classRef size bits o nBytes nInsts flags indexTypeFlags imgAddr
   179     |addr classPtr classRef size bits o nBytes nInsts flags indexTypeFlags imgAddr
   177      |
   180      |
   178 
   181 
   179     baseAddr == 0 ifTrue:[^ nil].
   182     baseAddr == 0 ifTrue:[^ nil].
   180     (baseAddr bitAnd:1) == 1 ifTrue:[(baseAddr bitTest:16r80000000) ifTrue:[
   183     (baseAddr bitAnd:1) == 1 ifTrue:[
   181                                          ^ (baseAddr - 16r100000000) bitShift32:-1
   184         (baseAddr bitTest:16r80000000) ifTrue:[
   182                                      ] ifFalse:[   
   185             ^ (baseAddr - 16r100000000) bitShift32:-1
   183                                          ^ baseAddr bitShift32:-1
   186         ] ifFalse:[   
   184                                      ]
   187             ^ baseAddr bitShift32:-1
   185                                     ].
   188         ]
       
   189     ].
   186     (baseAddr bitAnd:3) ~~ 0 ifTrue:[self halt].
   190     (baseAddr bitAnd:3) ~~ 0 ifTrue:[self halt].
   187 
   191 
   188     o := addrToObjectMapping at:baseAddr ifAbsent:nil.
   192     o := addrToObjectMapping at:(baseAddr bitShift:-2) ifAbsent:nil.
   189     o notNil ifTrue:[^ o].
   193     o notNil ifTrue:[^ o].
   190 
   194 
   191     addr := baseAddr.
   195     addr := baseAddr.
   192     classPtr := self fetchPointerAt:addr.
   196     classPtr := self fetchPointerAt:addr.
   193     addr := addr + ptrSize.
   197     addr := addr + ptrSize.
   205     flags := classRef flags.
   209     flags := classRef flags.
   206     indexTypeFlags := flags bitAnd:Behavior maskIndexType.
   210     indexTypeFlags := flags bitAnd:Behavior maskIndexType.
   207     (indexTypeFlags = Behavior flagBytes) ifTrue:[ 
   211     (indexTypeFlags = Behavior flagBytes) ifTrue:[ 
   208         nBytes := (size - (intSize * 3)).
   212         nBytes := (size - (intSize * 3)).
   209         o := ImageByteObject new:nBytes.
   213         o := ImageByteObject new:nBytes.
       
   214         o memory:self.
       
   215         o address:baseAddr.
   210         o classRef:classRef.
   216         o classRef:classRef.
   211 "/ size > 8000 ifTrue:[self halt].
   217 "/ size > 8000 ifTrue:[self halt].
   212         o byteSize:size.
   218         o byteSize:size.
   213         o bits:bits.
   219         o bits:bits.
       
   220         addrToObjectMapping at:(baseAddr bitShift:-2) put:o.
   214 
   221 
   215         imgAddr := self imageAddressOf:addr.
   222         imgAddr := self imageAddressOf:addr.
   216         stream position:imgAddr.
   223         stream position:imgAddr.
   217 
   224 
   218         1 to:nBytes do:[:idx |
   225         1 to:nBytes do:[:idx |
   243                 o := ImageMethodObject new:nInsts.
   250                 o := ImageMethodObject new:nInsts.
   244             ] ifFalse:[
   251             ] ifFalse:[
   245                 o := ImageObject new:nInsts.
   252                 o := ImageObject new:nInsts.
   246             ]
   253             ]
   247         ].
   254         ].
       
   255         o memory:self.
       
   256         o address:baseAddr.
   248         o classRef:classRef.
   257         o classRef:classRef.
   249 size > 8000 ifTrue:[self halt].
   258 size > 8000 ifTrue:[self halt].
   250         o byteSize:size.
   259         o byteSize:size.
   251         o bits:bits.
   260         o bits:bits.
   252         addrToObjectMapping at:baseAddr put:o.
   261         addrToObjectMapping at:(baseAddr bitShift:-2) put:o.
   253 
   262 
   254         1 to:nInsts do:[:idx |
   263         1 to:nInsts do:[:idx |
   255             o at:idx put:(self fetchUnboxedIntegerAt:addr).
   264             o at:idx put:(self fetchUnboxedIntegerAt:addr).
   256 "/            o at:idx put:(self fetchObjectAt:(self fetchUnboxedIntegerAt:addr)).
   265 "/            o at:idx put:(self fetchObjectAt:(self fetchUnboxedIntegerAt:addr)).
   257             addr := addr + ptrSize.
   266             addr := addr + ptrSize.
   258         ]
   267         ]
   259     ].
   268     ].
   260     o memory:self.
       
   261     ^ o
   269     ^ o
   262 !
   270 !
   263 
   271 
   264 fetchPointerAt:addr
   272 fetchPointerAt:addr
   265     ^ self fetchUnboxedIntegerAt:addr
   273     ^ self fetchUnboxedIntegerAt:addr
   325 
   333 
   326 for:aFilename
   334 for:aFilename
   327     stream := aFilename asFilename readStream binary.
   335     stream := aFilename asFilename readStream binary.
   328     addrToObjectMapping := IdentityDictionary new.
   336     addrToObjectMapping := IdentityDictionary new.
   329 
   337 
   330     addrToObjectMapping at:(ObjectMemory addressOf:false) put:false.
   338     addrToObjectMapping at:((ObjectMemory addressOf:false) bitShift:-2) put:false.
   331     addrToObjectMapping at:(ObjectMemory addressOf:true) put:true.
   339     addrToObjectMapping at:((ObjectMemory addressOf:true) bitShift:-2)  put:true.
   332 !
   340 !
   333 
   341 
   334 printStringOfClass:aClassRef
   342 printStringOfClass:aClassRef
   335     |nameSlot|
   343     |nameSlot|
   336 
   344 
   410 !
   418 !
   411 
   419 
   412 readHeader
   420 readHeader
   413         "
   421         "
   414          (self for:'stmeas.img') readHeader
   422          (self for:'stmeas.img') readHeader
       
   423          (self for:'crash.img') readHeader
   415         "
   424         "
   416 
   425 
   417         |order magic version timeStamp snapID last_util_addr hiText_addr flags 
   426         |order magic version timeStamp snapID last_util_addr hiText_addr flags 
   418          lowData hiData charSlots charTableSlots fixMemStart fixMemEnd 
   427          lowData hiData charSlots charTableSlots fixMemStart fixMemEnd 
   419          symMemStart symMemEnd vmDataAddr sharedMethodCode sharedBlockCode 
   428          symMemStart symMemEnd vmDataAddr sharedMethodCode sharedBlockCode 
   420          nContexts contextSpace nRegistered symbolsSeqNr nSpaces 
   429          nContexts contextSpace nRegistered symbolsSeqNr nSpaces 
   421          classNameSize spaceSize|
   430          classNameSize spaceSize numCharSlots|
   422 
   431 
   423         stream next:256.        "/ skip execCmd
   432         stream next:256.        "/ skip execCmd
   424 
   433 
   425         msb := false.
   434         msb := false.
   426         order := stream nextUnsignedLongMSB:msb.        
   435         order := stream nextUnsignedLongMSB:msb.        
   478         nRegistered := stream nextUnsignedLongMSB:msb.
   487         nRegistered := stream nextUnsignedLongMSB:msb.
   479 
   488 
   480         version >= 8 ifTrue:[
   489         version >= 8 ifTrue:[
   481             version >= 9 ifTrue:[
   490             version >= 9 ifTrue:[
   482                 symbolsSeqNr := stream nextUnsignedLongMSB:msb.
   491                 symbolsSeqNr := stream nextUnsignedLongMSB:msb.
   483                 stream next:(intSize * 31).
   492                 version >= 10 ifTrue:[
       
   493                     numCharSlots := stream nextUnsignedLongMSB:msb.
       
   494                     stream next:(intSize * 30).
       
   495                 ] ifFalse:[
       
   496                     stream next:(intSize * 31).
       
   497                 ].
   484             ] ifFalse:[
   498             ] ifFalse:[
   485                 stream next:(intSize * 32).
   499                 stream next:(intSize * 32).
   486             ]
   500             ]
   487         ].
   501         ].
   488 
   502 
   501 
   515 
   502         1 to:nSpaces do:[:i |
   516         1 to:nSpaces do:[:i |
   503             (spaceInfos at:i) size:(stream nextUnsignedLongMSB:msb).
   517             (spaceInfos at:i) size:(stream nextUnsignedLongMSB:msb).
   504         ].
   518         ].
   505         nSpaces+1 to:32 do:[:i | stream nextUnsignedLongMSB:msb].
   519         nSpaces+1 to:32 do:[:i | stream nextUnsignedLongMSB:msb].
   506 
       
   507         version >= 8 ifTrue:[
   520         version >= 8 ifTrue:[
   508             stream position:(stream class zeroPosition).
   521             stream reset.
   509             stream skip:4096.
   522             stream skip:4096.
   510         ].
   523         ].
   511 
   524 
   512         1 to:nSpaces do:[:i |
   525         1 to:nSpaces do:[:i |
   513             (spaceInfos at:i) end:((spaceInfos at:i) start + (spaceInfos at:i) size - 1).
   526             (spaceInfos at:i) end:((spaceInfos at:i) start + (spaceInfos at:i) size - 1).
   702         ] whileTrue
   715         ] whileTrue
   703 ! !
   716 ! !
   704 
   717 
   705 !SnapShotImageMemory::ImageHeader methodsFor:'accessing'!
   718 !SnapShotImageMemory::ImageHeader methodsFor:'accessing'!
   706 
   719 
       
   720 address:something
       
   721     address := something.
       
   722 !
       
   723 
   707 bits
   724 bits
   708     "return the value of the instance variable 'bits' (automatically generated)"
   725     "return the value of the instance variable 'bits' (automatically generated)"
   709 
   726 
   710     ^ bits
   727     ^ bits
   711 !
   728 !
  2473     "Created: / 10.12.1995 / 16:31:25 / cg"
  2490     "Created: / 10.12.1995 / 16:31:25 / cg"
  2474     "Modified: / 1.4.1997 / 16:00:33 / stefan"
  2491     "Modified: / 1.4.1997 / 16:00:33 / stefan"
  2475     "Modified: / 3.2.2000 / 23:05:28 / cg"
  2492     "Modified: / 3.2.2000 / 23:05:28 / cg"
  2476 !
  2493 !
  2477 
  2494 
       
  2495 fileOutCommentOn:aStream
       
  2496     "append an expression on aStream, which defines my comment"
       
  2497 
       
  2498     |comment s|
       
  2499 
       
  2500     self printClassNameOn:aStream.
       
  2501     aStream nextPutAll:' comment:'.
       
  2502     (comment := self comment) isNil ifTrue:[
       
  2503         s := ''''''
       
  2504     ] ifFalse:[
       
  2505         s := comment storeString
       
  2506     ].
       
  2507     aStream nextPutAllAsChunk:s.
       
  2508     aStream nextPutChunkSeparator.
       
  2509     aStream cr
       
  2510 !
       
  2511 
  2478 fileOutDefinitionOn:aStream
  2512 fileOutDefinitionOn:aStream
  2479     "append an expression on aStream, which defines myself."
  2513     "append an expression on aStream, which defines myself."
  2480 
  2514 
  2481     ^ self basicFileOutDefinitionOn:aStream withNameSpace:false
  2515     ^ self basicFileOutDefinitionOn:aStream withNameSpace:false
  2482 !
  2516 !
  3956 !
  3990 !
  3957 
  3991 
  3958 isMeta
  3992 isMeta
  3959     |clsName|
  3993     |clsName|
  3960 
  3994 
       
  3995     thisContext isRecursive ifTrue:[^ false].
       
  3996     byteSize = (Metaclass instSize * 4 + 12) ifFalse:[^ false].
       
  3997 
  3961     clsName := classRef name.
  3998     clsName := classRef name.
  3962     ^ clsName = 'Metaclass' or:[clsName = 'PrivateMetaclass'].
  3999     ^ clsName = 'Metaclass' or:[clsName = 'PrivateMetaclass'].
  3963 
  4000 
  3964 "/self halt.
  4001 "/self halt.
  3965 "/    ^ self size == (Metaclass instSize).
  4002 "/    ^ self size == (Metaclass instSize).
  3978 isPrivate
  4015 isPrivate
  3979     ^ classRef isPrivateMeta 
  4016     ^ classRef isPrivateMeta 
  3980 !
  4017 !
  3981 
  4018 
  3982 isPrivateMeta
  4019 isPrivateMeta
       
  4020     thisContext isRecursive ifTrue:[^ false].
       
  4021     byteSize = (PrivateMetaclass instSize * 4 + 12) ifFalse:[^ false].
  3983     ^ classRef name = 'PrivateMetaclass'
  4022     ^ classRef name = 'PrivateMetaclass'
  3984 !
  4023 !
  3985 
  4024 
  3986 isSignedLongLongs
  4025 isSignedLongLongs
  3987     ^ (self flags bitAnd:Behavior maskIndexType) == Behavior flagSignedLongLongs.
  4026     ^ (self flags bitAnd:Behavior maskIndexType) == Behavior flagSignedLongLongs.