Oct 6th 1999.

NewSpace Code Sample


'From VisualWorks(R), Release 2.5 of September 26, 1995 on May 5, 1996 at 10:19:23 pm'! Object subclass: #EarlyTenureTest instanceVariableNames: 'holdTooLong counter allocationSize trackAllocations logStream canStop waitSync ' classVariableNames: '' poolDictionaries: '' category: 'JMM-Memory-Paper'! EarlyTenureTest comment: '1996 John M McIntosh, All Rights Reserved. johnmci@ibm.net A object that creates the Early Tenure problem so we can examine NewSpace behavoir. . Instance Variables: holdTooLong <Array> holder for strings of size allocationSize counter <Integer> iterates over the array to place elements allocationSize <Integer> holds current allocation size for Strings trackAllocations <Integer> hold total number of allocations logStream <Stream> log of information about test cycle canStop <Boolean> true when I can stop waitSync <Semaphore> used to sync work and result log Note to test this you must invoke the sizesAtStartup: then quit/save your image. After restart of the image invoke thresholds: to reset the NewSpace memory threshold You may need to adjust sizesAtStartup: if your installation has already altered some of the other memory space sizes. ObjectMemory sizesAtStartup: #(1.0 7.0 1.0 1.0 1.0 1.0). ObjectMemory thresholds: #(0.96 0.95 0.90)'! !EarlyTenureTest methodsFor: 'actions'! createElement self holdTooLong at: self incrementCounter put: (String new: self allocationSize)! incrementCounter self trackAllocations: self trackAllocations + 1. ^counter := counter >= self defaultCounter ifTrue: [1] ifFalse: [counter + 1]! runForThisManySeconds: aNumber "Fork the delay timer, fork the work, when done return the logStream contents" self forkTimer: aNumber. self forkAllocation. self waitSync wait. ^self logStream contents! writeSize "Print the time, memory footprint, scavenges and total allocations for our records" self logStream nextPutAll: Time now printString; space; nextPutAll: ObjectMemory dynamicallyAllocatedFootprint printString; space; nextPutAll: ObjectMemory current numScavenges printString; space; nextPutAll: trackAllocations printString; cr! ! !EarlyTenureTest methodsFor: 'defaults'! defaultCounter ^500! defaultPriority ^Processor userBackgroundPriority! defaultSize "Do not change over 1000 bytes " ^512! ! !EarlyTenureTest methodsFor: 'accessing'! allocationSize ^allocationSize isNil ifTrue: [allocationSize := self defaultSize] ifFalse: [allocationSize]! allocationSize: aNumber allocationSize := aNumber! canStop ^canStop! canStop: aFlag canStop := aFlag! holdTooLong ^holdTooLong! holdTooLong: anArray holdTooLong := anArray! logStream ^logStream! logStream: aStream logStream := aStream! trackAllocations ^trackAllocations! trackAllocations: aNumber trackAllocations := aNumber! waitSync ^waitSync! waitSync: aSync waitSync := aSync! ! !EarlyTenureTest methodsFor: 'initialize-release'! initialize holdTooLong := Array new: self defaultCounter. counter := 0. logStream := WriteStream on: (String new: 1024). canStop := false. trackAllocations := 0. waitSync := Semaphore new! ! !EarlyTenureTest methodsFor: 'forks'! forkAllocation [self writeSize. [self canStop] whileFalse: [self createElement]. self writeSize. self waitSync signal] forkAt: self defaultPriority! forkTimer: aNumber [(Delay forSeconds: aNumber) wait. self canStop: true] forkAt: self defaultPriority + 1.! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! EarlyTenureTest class instanceVariableNames: ''! !EarlyTenureTest class methodsFor: 'instance creation'! new ^super new initialize! ! !EarlyTenureTest class methodsFor: 'Example'! example ^self new allocationSize: 128; runForThisManySeconds: 15.! !