ObjectMemory.st
branchjv
changeset 18120 e3a375d5f6a8
parent 18094 1a573db27ac4
parent 17532 f71ff4160e94
child 18403 9a3fc7cc7127
equal deleted inserted replaced
18119:cb7a12afe736 18120:e3a375d5f6a8
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 "{ Package: 'stx:libbasic' }"
    12 "{ Package: 'stx:libbasic' }"
       
    13 
       
    14 "{ NameSpace: Smalltalk }"
    13 
    15 
    14 Object subclass:#ObjectMemory
    16 Object subclass:#ObjectMemory
    15 	instanceVariableNames:''
    17 	instanceVariableNames:''
    16 	classVariableNames:'InternalErrorHandler UserInterruptHandler TimerInterruptHandler
    18 	classVariableNames:'InternalErrorHandler UserInterruptHandler TimerInterruptHandler
    17 		SpyInterruptHandler StepInterruptHandler
    19 		SpyInterruptHandler StepInterruptHandler
   667 !ObjectMemory class methodsFor:'initialization'!
   669 !ObjectMemory class methodsFor:'initialization'!
   668 
   670 
   669 initialize
   671 initialize
   670     "initialize the class"
   672     "initialize the class"
   671 
   673 
       
   674     "/ protect against double initialization
   672     AllocationFailureSignal isNil ifTrue:[
   675     AllocationFailureSignal isNil ifTrue:[
   673 	AllocationFailureSignal := AllocationFailure.
   676         AllocationFailureSignal := AllocationFailure.
   674 	AllocationFailureSignal notifierString:'allocation failure'.
   677         AllocationFailureSignal notifierString:'allocation failure'.
   675 
   678 
   676 	MallocFailureSignal := MallocFailure.
   679         MallocFailureSignal := MallocFailure.
   677 	MallocFailureSignal notifierString:'(malloc) allocation failure'.
   680         MallocFailureSignal notifierString:'(malloc) allocation failure'.
   678 
   681 
   679 	LowSpaceSemaphore := Semaphore new name:'LowSpaceSemaphore'
   682         LowSpaceSemaphore := Semaphore new name:'LowSpaceSemaphore'.
   680     ].
   683 
   681     DisposeInterruptHandler := self.
   684         DisposeInterruptHandler := self.
   682 
   685 
   683     "/ BackgroundCollectMaximumInterval := 3600.     "/ run it at least once an hour
   686         "/ BackgroundCollectMaximumInterval := 3600.     "/ run it at least once an hour
   684     BackgroundCollectMaximumInterval := nil.      "/ only run when space situation makes it feasable
   687         BackgroundCollectMaximumInterval := nil.      "/ only run when space situation makes it feasable
   685     IncrementalGCLimit := 500000.                 "/ run it whenever 500k have been allocated
   688         IncrementalGCLimit := 500000.                 "/ run it whenever 500k have been allocated
   686     FreeSpaceGCLimit := FreeSpaceGCAmount := nil. "/ no minumum-freeSpace trigger.
   689         FreeSpaceGCLimit := FreeSpaceGCAmount := nil. "/ no minumum-freeSpace trigger.
   687     MemoryInterruptHandler := self.
   690         MemoryInterruptHandler := self.
   688     ExceptionInterruptHandler := self.
   691         ExceptionInterruptHandler := self.
   689 
   692 
   690     VMSelectors := #( #noByteCode #invalidCodeObject #invalidByteCode #invalidInstruction
   693         VMSelectors := #( #noByteCode #invalidCodeObject #invalidByteCode #invalidInstruction
   691 		      #tooManyArguments #badLiteralTable #receiverNotBoolean: #typeCheckError
   694                           #tooManyArguments #badLiteralTable #receiverNotBoolean: #typeCheckError
   692 		      #integerCheckError #wrongNumberOfArguments: #privateMethodCalled
   695                           #integerCheckError #wrongNumberOfArguments: #privateMethodCalled
   693 		      #doesNotUnderstand: #invalidReturn: #invalidReturnOrRestart:
   696                           #doesNotUnderstand: #invalidReturn: #invalidReturnOrRestart:
   694 		      #userInterrupt #internalError: #spyInterrupt #timerInterrupt #stepInterrupt
   697                           #userInterrupt #internalError: #spyInterrupt #timerInterrupt #stepInterrupt
   695 		      #errorInterrupt:with: #disposeInterrupt #recursionInterrupt
   698                           #errorInterrupt:with: #disposeInterrupt #recursionInterrupt
   696 		      #memoryInterrupt #fpExceptionInterrupt #signalInterrupt: #childSignalInterrupt
   699                           #memoryInterrupt #fpExceptionInterrupt #signalInterrupt: #childSignalInterrupt
   697 		      #ioInterrupt #customInterrupt #schedulerInterrupt #contextInterrupt
   700                           #ioInterrupt #customInterrupt #schedulerInterrupt #contextInterrupt
   698 		      #interruptLatency:receiver:class:selector:vmActivity:id:).
   701                           #interruptLatency:receiver:class:selector:vmActivity:id:).
       
   702     ]
   699 
   703 
   700     "Modified: / 5.8.1998 / 15:30:12 / cg"
   704     "Modified: / 5.8.1998 / 15:30:12 / cg"
   701 ! !
   705 ! !
   702 
   706 
   703 !ObjectMemory class methodsFor:'Compatibility-ST80'!
   707 !ObjectMemory class methodsFor:'Compatibility-ST80'!
   946     to use.
   950     to use.
   947 
   951 
   948     Occasionally, the VM needs to unwind-protect some C code.
   952     Occasionally, the VM needs to unwind-protect some C code.
   949     If so, it creates and artificial context on the stack and
   953     If so, it creates and artificial context on the stack and
   950     marks it for unwind, so stack unwinding logic finds it
   954     marks it for unwind, so stack unwinding logic finds it
   951     and handles it. 
   955     and handles it.
   952 
   956 
   953     Now, only #lookupMethodForSelectorUnwindProtect is supported
   957     Now, only #lookupMethodForSelectorUnwindProtect is supported
   954     (ensures the lookup is popped out from the lookupActications)
   958     (ensures the lookup is popped out from the lookupActications)
   955     "
   959     "
   956     aContext selector == #lookupMethodForSelectorUnwindHandlerFor: ifTrue:[
   960     aContext selector == #lookupMethodForSelectorUnwindHandlerFor: ifTrue:[
   957         ^[self lookupMethodForSelectorUnwindHandlerFor: (aContext argAt: 1)]
   961 	^[self lookupMethodForSelectorUnwindHandlerFor: (aContext argAt: 1)]
   958     ].                                                
   962     ].
   959 
   963 
   960     self internalError:'Unknown VM unwind protect action'
   964     self internalError:'Unknown VM unwind protect action'
   961 
   965 
   962     "Created: / 01-10-2011 / 19:15:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   966     "Created: / 01-10-2011 / 19:15:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   963 ! !
   967 ! !
  1063 
  1067 
  1064     self flushMethodCacheForSelector:aSelector.
  1068     self flushMethodCacheForSelector:aSelector.
  1065 
  1069 
  1066     "/ self flushInlineCachesForSelector:aSelector.
  1070     "/ self flushInlineCachesForSelector:aSelector.
  1067     self flushInlineCachesWithArgs:(aSelector numArgs).
  1071     self flushInlineCachesWithArgs:(aSelector numArgs).
       
  1072 !
       
  1073 
       
  1074 flushCachesForSelector:aSelector numArgs:numArgs
       
  1075     "flush method and inline caches for aSelector"
       
  1076 
       
  1077     self flushMethodCacheForSelector:aSelector.
       
  1078 
       
  1079     "/ self flushInlineCachesForSelector:aSelector.
       
  1080     self flushInlineCachesWithArgs:numArgs.
  1068 !
  1081 !
  1069 
  1082 
  1070 flushInlineCaches
  1083 flushInlineCaches
  1071     "flush all inlinecaches"
  1084     "flush all inlinecaches"
  1072 
  1085 
  1416         owners := "Weak"IdentitySet new.
  1429         owners := "Weak"IdentitySet new.
  1417 
  1430 
  1418         numObjectsDone := 0.
  1431         numObjectsDone := 0.
  1419         found := false.
  1432         found := false.
  1420 
  1433 
  1421         AbortOperationRequest handle:[]
  1434         AbortOperationRequest catch:[
  1422         do:[
  1435             self allObjectsIncludingContextsDo:[:o |
  1423             [self allObjectsIncludingContextsDo:[:o |
       
  1424                 |inPrevLevel isOwner|
  1436                 |inPrevLevel isOwner|
  1425 
  1437 
  1426                 stop ifTrue:[AbortOperationRequest raise].
  1438                 stop ifTrue:[AbortOperationRequest raise].
  1427                 stop ifFalse:[
  1439                 stop ifFalse:[
  1428                     isOwner := false.
  1440                     isOwner := false.
  1468                             progress percentage:(numObjectsDone / numObjects * 100).
  1480                             progress percentage:(numObjectsDone / numObjects * 100).
  1469                             Processor yield.
  1481                             Processor yield.
  1470                         ]
  1482                         ]
  1471                     ]
  1483                     ]
  1472                 ]
  1484                 ]
  1473             ]] whileFalse.
  1485             ].
  1474         ].
  1486         ].
  1475         progress percentage:100.
  1487         progress percentage:100.
  1476 
  1488 
  1477         numObjects isNil ifTrue:[
  1489         numObjects isNil ifTrue:[
  1478             numObjects := numObjectsDone.
  1490             numObjects := numObjectsDone.
  1542 
  1554 
  1543                     lbl label:('found a reference chain.').
  1555                     lbl label:('found a reference chain.').
  1544                     progress beInvisible.
  1556                     progress beInvisible.
  1545 
  1557 
  1546                     chain addFirst:Smalltalk.
  1558                     chain addFirst:Smalltalk.
  1547                     list := OrderedCollection withSize:chain size.
  1559                     list := OrderedCollection newWithSize:chain size.
  1548                     1 to:chain size-1 do:[:i |
  1560                     1 to:chain size-1 do:[:i |
  1549                         list
  1561                         list
  1550                             at:i
  1562                             at:i
  1551                             put:(self refNameFor:(chain at:i+1) in:(chain at:i))
  1563                             put:(self refNameFor:(chain at:i+1) in:(chain at:i))
  1552                     ].
  1564                     ].
  1789 			to:anObject
  1801 			to:anObject
  1790 			inRefSets:levels
  1802 			inRefSets:levels
  1791 			startingAt:(index+1).
  1803 			startingAt:(index+1).
  1792 
  1804 
  1793 	    chain notNil ifTrue:[
  1805 	    chain notNil ifTrue:[
  1794 		(levels at:index) saveRemove:el.
  1806 		(levels at:index) safeRemove:el.
  1795 		chain addFirst:el. "/ (self refNameFor:el in:start).
  1807 		chain addFirst:el. "/ (self refNameFor:el in:start).
  1796 		^ chain.
  1808 		^ chain.
  1797 	    ]
  1809 	    ]
  1798 	].
  1810 	].
  1799 ].
  1811 ].
  1848 			to:anObject
  1860 			to:anObject
  1849 			inRefSets:levels
  1861 			inRefSets:levels
  1850 			startingAt:(index+1).
  1862 			startingAt:(index+1).
  1851 
  1863 
  1852 	    chain size > 0 ifTrue:[
  1864 	    chain size > 0 ifTrue:[
  1853 		(levels at:index) saveRemove:el.
  1865 		(levels at:index) safeRemove:el.
  1854 
  1866 
  1855 		c := chain copy.
  1867 		c := chain copy.
  1856 		c addFirst:el "(self refNameFor:el in:start)".
  1868 		c addFirst:el "(self refNameFor:el in:start)".
  1857 		chains add:c.
  1869 		chains add:c.
  1858 	    ]
  1870 	    ]
  1884 	    ]
  1896 	    ]
  1885 	].
  1897 	].
  1886     ] ifFalse:[
  1898     ] ifFalse:[
  1887 	names := referent class allInstVarNames.
  1899 	names := referent class allInstVarNames.
  1888 	oClass := referent class.
  1900 	oClass := referent class.
       
  1901 	oClass == anObject ifTrue:[
       
  1902 	    ^ oClass name.
       
  1903 	].
  1889 	1 to:oClass instSize do:[:i |
  1904 	1 to:oClass instSize do:[:i |
  1890 	    ((referent instVarAt:i) == anObject) ifTrue:[
  1905 	    ((referent instVarAt:i) == anObject) ifTrue:[
  1891 		^ '%1 [%2]' bindWith:referent classNameWithArticle with:(names at:i) allBold.
  1906 		^ '%1 [%2]' bindWith:referent classNameWithArticle with:(names at:i) allBold.
  1892 	    ].
  1907 	    ].
  1893 	].
  1908 	].
  2314      backgroundCollector."
  2329      backgroundCollector."
  2315 
  2330 
  2316     |done limit|
  2331     |done limit|
  2317 
  2332 
  2318     AbortOperationRequest handle:[:ex |
  2333     AbortOperationRequest handle:[:ex |
  2319         "/ in case of abort (from the debugger),
  2334 	"/ in case of abort (from the debugger),
  2320         "/ disable gcSteps.
  2335 	"/ disable gcSteps.
  2321         done := true.
  2336 	done := true.
  2322         IncrementalGCLimit := FreeSpaceGCLimit := nil.
  2337 	IncrementalGCLimit := FreeSpaceGCLimit := nil.
  2323         'ObjectMemory [error]: IGC aborted; turning off incremental GC' errorPrintCR
  2338 	'ObjectMemory [error]: IGC aborted; turning off incremental GC' errorPrintCR
  2324     ] do:[
  2339     ] do:[
  2325         limit := IncrementalGCLimit.
  2340 	limit := IncrementalGCLimit.
  2326         (limit notNil and:[self oldSpaceAllocatedSinceLastGC > limit]) ifTrue:[
  2341 	(limit notNil and:[self oldSpaceAllocatedSinceLastGC > limit]) ifTrue:[
  2327 "/            'IGC [info]: start since allocatedSinceLastGC > IncrementalGCLimit' infoPrintCR.
  2342 "/            'IGC [info]: start since allocatedSinceLastGC > IncrementalGCLimit' infoPrintCR.
  2328             done := ObjectMemory gcStep
  2343 	    done := ObjectMemory gcStep
  2329         ] ifFalse:[
  2344 	] ifFalse:[
  2330             limit := FreeSpaceGCLimit.
  2345 	    limit := FreeSpaceGCLimit.
  2331             (limit notNil and:[(self freeSpace + self freeListSpace) < limit]) ifTrue:[
  2346 	    (limit notNil and:[(self freeSpace + self freeListSpace) < limit]) ifTrue:[
  2332 "/            'IGC [info]: start since freeSpace < FreeSpaceGCLimit' infoPrintCR.
  2347 "/            'IGC [info]: start since freeSpace < FreeSpaceGCLimit' infoPrintCR.
  2333                 done := ObjectMemory gcStep.
  2348 		done := ObjectMemory gcStep.
  2334                 done ifTrue:[
  2349 		done ifTrue:[
  2335                     self moreOldSpaceIfUseful
  2350 		    self moreOldSpaceIfUseful
  2336                 ].
  2351 		].
  2337             ] ifFalse:[
  2352 	    ] ifFalse:[
  2338                 limit := DynamicCodeGCTrigger.
  2353 		limit := DynamicCodeGCTrigger.
  2339                 (limit notNil and:[self compiledCodeCounter > limit]) ifTrue:[
  2354 		(limit notNil and:[self compiledCodeCounter > limit]) ifTrue:[
  2340 "/                    'IGC [info]: start since compiledCodeCounter > DynamicCodeGCTrigger' infoPrintCR.
  2355 "/                    'IGC [info]: start since compiledCodeCounter > DynamicCodeGCTrigger' infoPrintCR.
  2341                     done := ObjectMemory gcStep.
  2356 		    done := ObjectMemory gcStep.
  2342                 ] ifFalse:[
  2357 		] ifFalse:[
  2343                     limit := DynamicCodeLimit.
  2358 		    limit := DynamicCodeLimit.
  2344                     (limit notNil and:[self compiledCodeSpaceUsed > limit]) ifTrue:[
  2359 		    (limit notNil and:[self compiledCodeSpaceUsed > limit]) ifTrue:[
  2345 "/                    'IGC [info]: start since compiledCodeSpaceUsed > DynamicCodeLimit' infoPrintCR.
  2360 "/                    'IGC [info]: start since compiledCodeSpaceUsed > DynamicCodeLimit' infoPrintCR.
  2346                         done := ObjectMemory gcStep.
  2361 			done := ObjectMemory gcStep.
  2347                     ] ifFalse:[
  2362 		    ] ifFalse:[
  2348                         done := true
  2363 			done := true
  2349                     ]
  2364 		    ]
  2350                 ]
  2365 		]
  2351             ]
  2366 	    ]
  2352         ].
  2367 	].
  2353     ].
  2368     ].
  2354     ^ done not
  2369     ^ done not
  2355 
  2370 
  2356     "Modified: / 14.8.1998 / 13:08:15 / cg"
  2371     "Modified: / 14.8.1998 / 13:08:15 / cg"
  2357 !
  2372 !
  2504 
  2519 
  2505 		[true] whileTrue:[
  2520 		[true] whileTrue:[
  2506 		    doGC := self gcStepIfUseful.
  2521 		    doGC := self gcStepIfUseful.
  2507 		    doGC ifFalse:[
  2522 		    doGC ifFalse:[
  2508 			(BackgroundCollectMaximumInterval notNil
  2523 			(BackgroundCollectMaximumInterval notNil
  2509 			and:[(Timestamp now getSeconds - timeOfLastGC getSeconds) > BackgroundCollectMaximumInterval])
  2524 			and:[(Timestamp now secondDeltaFrom: timeOfLastGC) > BackgroundCollectMaximumInterval])
  2510 			ifTrue:[
  2525 			ifTrue:[
  2511 "/                            'ObjectMemory [info]: start time-triggered background collect.' infoPrintCR.
  2526 "/                            'ObjectMemory [info]: start time-triggered background collect.' infoPrintCR.
  2512 			    doGC := true.
  2527 			    doGC := true.
  2513 			]
  2528 			]
  2514 		    ].
  2529 		    ].
  4170 finalize
  4185 finalize
  4171     "tell all weak objects that something happened."
  4186     "tell all weak objects that something happened."
  4172 
  4187 
  4173     self allChangedShadowObjectsDo:[:aShadowArray |
  4188     self allChangedShadowObjectsDo:[:aShadowArray |
  4174 	Error handle:[:ex |
  4189 	Error handle:[:ex |
  4175 	    'ObjectMemory [warning]: cought error in weakArray processing: ' errorPrint.
  4190 	    'ObjectMemory [warning]: caught error in weakArray processing: ' errorPrint.
  4176 	    ex description errorPrintCR.
  4191 	    ex description errorPrintCR.
  4177 	    ex suspendedContext fullPrintAllLevels:10.
  4192 	    ex suspendedContext fullPrintAllLevels:10.
  4178 	    "Restart the do block to clean up the rest of the shadow array.
  4193 	    "Restart the do block to clean up the rest of the shadow array.
  4179 	     This is safe here, because the old executor that triggered the error
  4194 	     This is safe here, because the old executor that triggered the error
  4180 	     has already been removed from the Registry"
  4195 	     has already been removed from the Registry"
  4383     RETURN(__mkSmallInteger(0));
  4398     RETURN(__mkSmallInteger(0));
  4384 #endif
  4399 #endif
  4385 %}
  4400 %}
  4386 
  4401 
  4387     "
  4402     "
  4388         self collectedOldSpaceAddress
  4403 	self collectedOldSpaceAddress
  4389     "
  4404     "
  4390 !
  4405 !
  4391 
  4406 
  4392 fixSpaceSize
  4407 fixSpaceSize
  4393     "return the total size of the fix space."
  4408     "return the total size of the fix space."
  4723     RETURN(__mkSmallInteger(0));
  4738     RETURN(__mkSmallInteger(0));
  4724 #endif
  4739 #endif
  4725 %}
  4740 %}
  4726 
  4741 
  4727     "
  4742     "
  4728         self oldSpaceAddress
  4743 	self oldSpaceAddress
  4729     "
  4744     "
  4730 !
  4745 !
  4731 
  4746 
  4732 oldSpaceAllocatedSinceLastGC
  4747 oldSpaceAllocatedSinceLastGC
  4733     "return the number of bytes allocated for old objects since the
  4748     "return the number of bytes allocated for old objects since the
  5039 
  5054 
  5040     |modules|
  5055     |modules|
  5041 
  5056 
  5042     modules := IdentityDictionary new.
  5057     modules := IdentityDictionary new.
  5043     self allBinaryModulesDo:[:idArg :nameArg :flagsArg :libName :timeStamp |
  5058     self allBinaryModulesDo:[:idArg :nameArg :flagsArg :libName :timeStamp |
  5044 	|type subModuleName module dynamic infoRec handle pathName
  5059         |type subModuleName module dynamic infoRec handle pathName
  5045 	 typeName name nameString|
  5060          typeName name nameString|
  5046 
  5061 
  5047 	nameArg class == String ifFalse:[
  5062         nameArg isString ifFalse:[
  5048 	    'Error in binaryModuleInfo - skip entry' errorPrintCR.
  5063             'Error in binaryModuleInfo - skip entry' errorPrintCR.
  5049 	] ifTrue:[
  5064         ] ifTrue:[
  5050 	    name := nameArg.
  5065             name := nameArg.
  5051 	    subModuleName := name asSymbol.
  5066             subModuleName := name asSymbol.
  5052 
  5067 
  5053 	    idArg > 0 ifTrue:[
  5068             idArg > 0 ifTrue:[
  5054 		dynamic := true.
  5069                 dynamic := true.
  5055 		typeName := 'dynamic '.
  5070                 typeName := 'dynamic '.
  5056 		handle := ObjectFileLoader handleFromID:idArg.
  5071                 handle := ObjectFileLoader handleFromID:idArg.
  5057 		(handle isNil or:[(pathName := handle pathName) isNil]) ifTrue:[
  5072                 (handle isNil or:[(pathName := handle pathName) isNil]) ifTrue:[
  5058 		    name := '?'
  5073                     name := '?'
  5059 		] ifFalse:[
  5074                 ] ifFalse:[
  5060 		    name := pathName asFilename baseName
  5075                     name := pathName asFilename baseName
  5061 		]
  5076                 ]
  5062 	    ] ifFalse:[
  5077             ] ifFalse:[
  5063 		dynamic := false.
  5078                 dynamic := false.
  5064 		typeName := 'builtIn '.
  5079                 typeName := 'builtIn '.
  5065 		pathName := nil.
  5080                 pathName := nil.
  5066 		libName isNil ifTrue:[
  5081                 libName isNil ifTrue:[
  5067 		    name := subModuleName
  5082                     name := subModuleName
  5068 		] ifFalse:[
  5083                 ] ifFalse:[
  5069 		    name := libName
  5084                     name := libName
  5070 		].
  5085                 ].
  5071 	    ].
  5086             ].
  5072 	    nameString := typeName.
  5087             nameString := typeName.
  5073 	    libName isNil ifTrue:[
  5088             libName isNil ifTrue:[
  5074 		nameString := nameString, 'module '
  5089                 nameString := nameString, 'module '
  5075 	    ] ifFalse:[
  5090             ] ifFalse:[
  5076 		nameString := nameString, 'classLib '
  5091                 nameString := nameString, 'classLib '
  5077 	    ].
  5092             ].
  5078 	    nameString := nameString , name.
  5093             nameString := nameString , name.
  5079 
  5094 
  5080 	    libName isNil ifTrue:[
  5095             libName isNil ifTrue:[
  5081 		type := #classObject
  5096                 type := #classObject
  5082 	    ] ifFalse:[
  5097             ] ifFalse:[
  5083 		type := #classLibrary
  5098                 type := #classLibrary
  5084 	    ].
  5099             ].
  5085 
  5100 
  5086 	    infoRec := modules at:idArg ifAbsent:nil.
  5101             infoRec := modules at:idArg ifAbsent:nil.
  5087 	    infoRec notNil ifTrue:[
  5102             infoRec notNil ifTrue:[
  5088 		infoRec classNames add:subModuleName.
  5103                 infoRec classNames add:subModuleName.
  5089 	    ] ifFalse:[
  5104             ] ifFalse:[
  5090 		infoRec := BinaryModuleDescriptor
  5105                 infoRec := BinaryModuleDescriptor
  5091 				name:nameString
  5106                                 name:nameString
  5092 				type:type
  5107                                 type:type
  5093 				id:idArg
  5108                                 id:idArg
  5094 				dynamic:dynamic
  5109                                 dynamic:dynamic
  5095 				classNames:( (OrderedSet ? Set) with:subModuleName)
  5110                                 classNames:( (OrderedSet ? Set) with:subModuleName)
  5096 				handle:handle
  5111                                 handle:handle
  5097 				pathName:pathName
  5112                                 pathName:pathName
  5098 				libraryName:libName
  5113                                 libraryName:libName
  5099 				timeStamp:nil.
  5114                                 timeStamp:nil.
  5100 
  5115 
  5101 		modules at:idArg put:infoRec.
  5116                 modules at:idArg put:infoRec.
  5102 	    ].
  5117             ].
  5103 	].
  5118         ].
  5104     ].
  5119     ].
  5105     ^ modules
  5120     ^ modules
  5106 
  5121 
  5107     "
  5122     "
  5108      ObjectMemory binaryModuleInfo
  5123      ObjectMemory binaryModuleInfo
  5128     "
  5143     "
  5129 ! !
  5144 ! !
  5130 
  5145 
  5131 !ObjectMemory class methodsFor:'system management'!
  5146 !ObjectMemory class methodsFor:'system management'!
  5132 
  5147 
       
  5148 directoryForImageAndChangeFile
       
  5149     |dir exeDir|
       
  5150 
       
  5151     dir := Filename currentDirectory.
       
  5152 
       
  5153     "/ the current directory is not a good idea, if stx is started via a desktop manager
       
  5154     "/ or in osx, by clicking on stx.app.
       
  5155     dir isRootDirectory ifTrue:[
       
  5156         exeDir := OperatingSystem nameOfSTXExecutable asFilename directory.
       
  5157         dir ~= exeDir ifTrue:[
       
  5158             "/ Change it to ~/.smalltalk or is executable directory better?
       
  5159 
       
  5160             "/ use executable dir, as otherwise I'd have to change the VM to include an image path...
       
  5161             "/ dir := Filename usersPrivateSmalltalkDirectory.
       
  5162             dir := exeDir.
       
  5163         ].
       
  5164     ].
       
  5165     ^ dir
       
  5166 
       
  5167     "
       
  5168      self directoryForImageAndChangeFile
       
  5169     "
       
  5170 !
       
  5171 
  5133 imageBaseName
  5172 imageBaseName
  5134     "return a reasonable filename to use as baseName (i.e. without extension).
  5173     "return a reasonable filename to use as baseName (i.e. without extension).
  5135      This is the filename of the current image (without '.img') or,
  5174      This is the filename of the current image (without '.img') or,
  5136      if not running from an image, the default name 'st'"
  5175      if not running from an image, the default name 'st'"
  5137 
  5176 
  5171      Return nil if not running from an image."
  5210      Return nil if not running from an image."
  5172 
  5211 
  5173     ^ ImageSaveTime
  5212     ^ ImageSaveTime
  5174 !
  5213 !
  5175 
  5214 
       
  5215 initChangeFilename
       
  5216     "/ make the changeFilePath an absolute one,
       
  5217     "/ in case some stupid windows fileDialog changes the current directory...
       
  5218     self
       
  5219         nameForChanges:(self directoryForImageAndChangeFile / ObjectMemory nameForChangesLocal)
       
  5220                             asAbsoluteFilename pathName
       
  5221 
       
  5222     "
       
  5223      self initChangeFilename
       
  5224     "
       
  5225 !
       
  5226 
  5176 nameForChanges
  5227 nameForChanges
  5177     "return a reasonable filename to store the changes into.
  5228     "return a reasonable filename to store the changes into.
  5178      Currently, this is defined in a classVariable and defaults to 'changes'.
  5229      By default, this is the basename of the current image with '.img' replaced
  5179      In future versions, this will be the basename of the current image with '.img' replaced
  5230      by '.chg', or, if not running from an image, the default name 'st.chg'.
  5180      by '.chg', or, if not running from an image, the default name 'st.chg'."
  5231      However, it can be overwritten via the nameForChanges: setter"
  5181 
  5232 
       
  5233     |nm|
       
  5234 
       
  5235     (nm := UserPreferences current changeFileName) notNil ifTrue:[
       
  5236 	^ nm
       
  5237     ].
  5182     ChangeFileName notNil ifTrue:[^ ChangeFileName].
  5238     ChangeFileName notNil ifTrue:[^ ChangeFileName].
  5183     ^ self nameForChangesLocal
  5239     ^ self nameForChangesLocal
  5184 
  5240 
  5185     "
  5241     "
  5186      ObjectMemory nameForChanges
  5242      ObjectMemory nameForChanges
  5286 refreshChangesFrom: oldChangesName
  5342 refreshChangesFrom: oldChangesName
  5287     "The snapshot image name has changed (snapshot saved),
  5343     "The snapshot image name has changed (snapshot saved),
  5288      the changes file must be copied to the new name.
  5344      the changes file must be copied to the new name.
  5289      No copy when the changes name is given explicitly."
  5345      No copy when the changes name is given explicitly."
  5290 
  5346 
  5291     ChangeFileName notNil ifTrue: [ ^self].
  5347     ChangeFileName notNil ifTrue: [
       
  5348 	ChangeFileName ~= self nameForChangesLocal ifTrue:[
       
  5349 	    ^ self
       
  5350 	]
       
  5351     ].
  5292     oldChangesName asFilename copyTo:self nameForChanges
  5352     oldChangesName asFilename copyTo:self nameForChanges
  5293 
  5353 
  5294     "Created: / 15.5.2004 / 20:29:03 / masca"
  5354     "Created: / 15.5.2004 / 20:29:03 / masca"
  5295 !
  5355 !
  5296 
  5356 
  5340      save in a temp file and rename - just in case something
  5400      save in a temp file and rename - just in case something
  5341      bad happens while writing the image.
  5401      bad happens while writing the image.
  5342      (could be ST/X error or file-system errors etc.)
  5402      (could be ST/X error or file-system errors etc.)
  5343     "
  5403     "
  5344     snapshotFilename := aFileName asFilename.
  5404     snapshotFilename := aFileName asFilename.
       
  5405     snapshotFilename isAbsolute ifFalse:[
       
  5406         snapshotFilename := self directoryForImageAndChangeFile
       
  5407                             / snapshotFilename name.
       
  5408     ].
       
  5409 
  5345     tempFilename := (FileStream newTemporaryIn:snapshotFilename directory)
  5410     tempFilename := (FileStream newTemporaryIn:snapshotFilename directory)
  5346                         close;
  5411                         close;
  5347                         fileName.
  5412                         fileName.
  5348     ok := self primSnapShotOn:tempFilename.
  5413     ok := self primSnapShotOn:tempFilename.
  5349 
  5414 
  5549     pathName := p.
  5614     pathName := p.
  5550 ! !
  5615 ! !
  5551 
  5616 
  5552 !ObjectMemory class methodsFor:'documentation'!
  5617 !ObjectMemory class methodsFor:'documentation'!
  5553 
  5618 
       
  5619 version
       
  5620     ^ '$Header: /cvs/stx/stx/libbasic/ObjectMemory.st,v 1.286 2015-02-20 22:45:22 cg Exp $'
       
  5621 !
       
  5622 
  5554 version_CVS
  5623 version_CVS
  5555     ^ '$Header: /cvs/stx/stx/libbasic/ObjectMemory.st,v 1.272 2013-08-19 10:02:34 stefan Exp $'
  5624     ^ '$Header: /cvs/stx/stx/libbasic/ObjectMemory.st,v 1.286 2015-02-20 22:45:22 cg Exp $'
  5556 !
  5625 !
  5557 
  5626 
  5558 version_SVN
  5627 version_SVN
  5559     ^ '$ Id: ObjectMemory.st 10643 2011-06-08 21:53:07Z vranyj1  $'
  5628     ^ '$ Id: ObjectMemory.st 10643 2011-06-08 21:53:07Z vranyj1  $'
  5560 ! !
  5629 ! !