ObjectMemory.st
changeset 19860 324edacff5cc
parent 19509 febba5cf48ca
child 19863 513bd7237fe7
child 20213 8e1886ca9293
--- a/ObjectMemory.st	Tue May 17 00:56:14 2016 +0200
+++ b/ObjectMemory.st	Tue May 17 02:04:25 2016 +0200
@@ -270,9 +270,9 @@
     Interestingly, the scavenger performs better, if many garbage objects
     are to be reclaimed, since less object-copying has to be done. Therefore,
     the best-case scavenge time is almost zero, if there is only garbage in
-    the newSpace. 
+    the newSpace.
     In contrast, the worst-case is when all newSpace objects are still living.
-    Thus, garbage reclamation of young objects is basically free - 
+    Thus, garbage reclamation of young objects is basically free -
     the more garbage is in newspace, the faster is the collector, asymptotically approaching
     zero time, when all new objects are garbage!!
 
@@ -313,9 +313,9 @@
 
     The blocking mark&sweep runs whenever the oldspace becomes full and the oldSpace
     limit has been reached (i.e. it prefers to map more pages to the oldSpace up to an
-    adjustable limit). It puts dead objects onto a free list. 
+    adjustable limit). It puts dead objects onto a free list.
     If a memory request cannot be served from this freelist,
-    and the total size of objects on the freelist exceeds a threshold (actually: the fragmentation does so), 
+    and the total size of objects on the freelist exceeds a threshold (actually: the fragmentation does so),
     the system will compress the oldspace to make the free-space into one big area.
     This compress is either done by a 1-pass semispace copy algorithm, or
     a 2pass inplace compress - depending on the setting of the compress limit
@@ -349,7 +349,7 @@
     (see ProcessorSceduler>>waitForEventOrTimeout), or alternatively as a low or high
     priority background process (see ObjectMemory>>startBackgroundCollector).
     Like the normal mark&sweep, this incremental collector follows object references
-    and marks reachable objects on its way. 
+    and marks reachable objects on its way.
     However, this is done 'a few objects-at-a-time', to not disrupt the system noticably.
     Currently, there are some (theoretical) and in practice never occurring situations,
     in which the incremental GC still creates noticable delays.
@@ -428,55 +428,55 @@
     Notice, that the defaults below are those of the VM and or ObjectMemory class.
     These may already be changed by a smalltalk.rc or private.rc startup file.
 
-            what        default     change by
-                                    command line arg    dynamically
+	    what        default     change by
+				    command line arg    dynamically
     -----------------------------------------------------------------------
-        newSpace size     400k      -Mnew nnn           newSpaceSize:nnn
-
-        oldSpace size    3000k      -Mold nnn           moreOldSpace:
-                                                        announceSpaceNeed:
-                                                        collectGarbage
-
-        max tenure age     29                           lockTenure:
-                                                        avoidTenure:
-                                                        (sets it to infinity)
-
-        adaptive tenure     -       -                   tenureParameters
-
-        2pass oldSpace
-        compressor      enabled     -Msingle            -
-
-        limit for 1pass
-        old-compress     8000k      -                   oldSpaceCompressLimit:
-
-        chunk size
-        to increase
-        oldSpace          256k      -                   oldSpaceIncrement:
-
-        prefer moreOld
-        to doing GC      false      -                   fastMoreOldSpaceAllocation:
-
-        limit for
-        above                -      -                   fastMoreOldSpaceLimit:
-
-        keep size for        -      -                   freeSpaceGCAmount:
-        IGC
-
-        low water
-        trigger for IGC      -      -                   freeSpaceGCLimit:
-
-        allocated
-        trigger for IGC   500k      -                   incrementalGCLimit
-
-        maximum time
-        interval between
-        IGC's                -      -                   BackgroundCollectMaximumInterval
-
-        JIT codeCache
-        size            unlimited   -                   dynamicCodeLimit:
-
-        new JIT code
-        trigger for IGC   none      -                   dynamicCodeGCTrigger:
+	newSpace size     400k      -Mnew nnn           newSpaceSize:nnn
+
+	oldSpace size    3000k      -Mold nnn           moreOldSpace:
+							announceSpaceNeed:
+							collectGarbage
+
+	max tenure age     29                           lockTenure:
+							avoidTenure:
+							(sets it to infinity)
+
+	adaptive tenure     -       -                   tenureParameters
+
+	2pass oldSpace
+	compressor      enabled     -Msingle            -
+
+	limit for 1pass
+	old-compress     8000k      -                   oldSpaceCompressLimit:
+
+	chunk size
+	to increase
+	oldSpace          256k      -                   oldSpaceIncrement:
+
+	prefer moreOld
+	to doing GC      false      -                   fastMoreOldSpaceAllocation:
+
+	limit for
+	above                -      -                   fastMoreOldSpaceLimit:
+
+	keep size for        -      -                   freeSpaceGCAmount:
+	IGC
+
+	low water
+	trigger for IGC      -      -                   freeSpaceGCLimit:
+
+	allocated
+	trigger for IGC   500k      -                   incrementalGCLimit
+
+	maximum time
+	interval between
+	IGC's                -      -                   BackgroundCollectMaximumInterval
+
+	JIT codeCache
+	size            unlimited   -                   dynamicCodeLimit:
+
+	new JIT code
+	trigger for IGC   none      -                   dynamicCodeGCTrigger:
 
 
     By default, no incremental GC is started by the system; however,
@@ -484,28 +484,28 @@
     You have to edit your startup files to change this.
     A suggested configuration (used by the author and the default) is:
 
-        ' keep 1meg in the pocket '
-
-        ObjectMemory freeSpaceGCAmount:1000000.
-
-        ' start incrementalGC when freespace drops below 250k '
-        ' or 500k of oldSpace has been allocated              '
-
-        ObjectMemory freeSpaceGCLimit:250000.                 '
-        ObjectMemory incrementalGCLimit:500000.               '
-
-        ' collect as a background process (the default is: at idle times)
-        ' this means that running cubes or other demo processes are suspended
-        ' for the collect; change the prio to below 4 if you want them to continue
-
-        ObjectMemory startBackgroundCollectorAt:5.            '
-        ObjectMemory startBackgroundFinalizationAt:5.         '
-
-        ' quickly allocate more space (i.e. avoid blocking collects)
-        ' up to 8meg - then start to collect if more memory is needed.
-
-        ObjectMemory fastMoreOldSpaceLimit:8*1024*1024.       '
-        ObjectMemory fastMoreOldSpaceAllocation:true.         '
+	' keep 1meg in the pocket '
+
+	ObjectMemory freeSpaceGCAmount:1000000.
+
+	' start incrementalGC when freespace drops below 250k '
+	' or 500k of oldSpace has been allocated              '
+
+	ObjectMemory freeSpaceGCLimit:250000.                 '
+	ObjectMemory incrementalGCLimit:500000.               '
+
+	' collect as a background process (the default is: at idle times)
+	' this means that running cubes or other demo processes are suspended
+	' for the collect; change the prio to below 4 if you want them to continue
+
+	ObjectMemory startBackgroundCollectorAt:5.            '
+	ObjectMemory startBackgroundFinalizationAt:5.         '
+
+	' quickly allocate more space (i.e. avoid blocking collects)
+	' up to 8meg - then start to collect if more memory is needed.
+
+	ObjectMemory fastMoreOldSpaceLimit:8*1024*1024.       '
+	ObjectMemory fastMoreOldSpaceAllocation:true.         '
 
   hints & tricks:
 
@@ -518,37 +518,37 @@
     control over allocation can speedup your programs; but please:
 
       - if you think you have to play around with the memory policies,
-        first check your program - you may find useless allocations
-        or bad uses of collections. A typical error that is made is to
-        create large collections using the #, (comma) concatenation method,
-        which shows square behavior, since it allocates many, many temporary
-        collections. Also, watch out for #copyWith:, #add: etc.
-        All of these create a new collection. Remember, that most collections
-        offer methods to preallocate some space; for example, 'Set new:' creates
-        an empty set, but preallocates space to avoid resizing over and over.
-
-        An especially bad performace dog is to use #add: on fix-size collection
-        objects (such as Strings or Arrays), since in addition to allocating
-        lots of garbage, a #become: operation is required for EACH element
-        added. NEVER use Arrays for growing/shrinking data - use OrderedCollection
-        instead. (if you really need an array, use asArray afterwards)
+	first check your program - you may find useless allocations
+	or bad uses of collections. A typical error that is made is to
+	create large collections using the #, (comma) concatenation method,
+	which shows square behavior, since it allocates many, many temporary
+	collections. Also, watch out for #copyWith:, #add: etc.
+	All of these create a new collection. Remember, that most collections
+	offer methods to preallocate some space; for example, 'Set new:' creates
+	an empty set, but preallocates space to avoid resizing over and over.
+
+	An especially bad performace dog is to use #add: on fix-size collection
+	objects (such as Strings or Arrays), since in addition to allocating
+	lots of garbage, a #become: operation is required for EACH element
+	added. NEVER use Arrays for growing/shrinking data - use OrderedCollection
+	instead. (if you really need an array, use asArray afterwards)
 
       - if you are going to allocate huge data structures, think about
-        optimizing space. For example, if you allocate a million instances of
-        some object, each added instance variable makes up 4Mb of additional
-        memory need.
-        Also, for Byte-valued, Integer-valued and Float like objects, special
-        collections are provided, which store their values directly inside (instead
-        of a reference to the object). A FloatArray consisting of 1 million floats
-        requires about 4mb of memory, while an Array of Floats requires 4mb for the
-        references to the floats, PLUS 20Mb for the floats themself.
+	optimizing space. For example, if you allocate a million instances of
+	some object, each added instance variable makes up 4Mb of additional
+	memory need.
+	Also, for Byte-valued, Integer-valued and Float like objects, special
+	collections are provided, which store their values directly inside (instead
+	of a reference to the object). A FloatArray consisting of 1 million floats
+	requires about 4mb of memory, while an Array of Floats requires 4mb for the
+	references to the floats, PLUS 20Mb for the floats themself.
 
       - check if you really need fast access to all of these objects; you may
-        try to only keep some subset in memory, and use binary storage or
-        (if this is too slow) optimized store/retrieve methods and keep the bigger
-        part in a file.
-        (How about a DiskArray class, which does this transparently ?
-         See the FileText class for some ideas and something to start with ...)
+	try to only keep some subset in memory, and use binary storage or
+	(if this is too slow) optimized store/retrieve methods and keep the bigger
+	part in a file.
+	(How about a DiskArray class, which does this transparently ?
+	 See the FileText class for some ideas and something to start with ...)
 
 
     Hint / Example 1:
@@ -1125,7 +1125,7 @@
 debugBreakPoint3
 
 %{
-#ifndef WIN32
+#ifndef __win32__
     /*extern void __debugBreakPoint3__();*/
     __debugBreakPoint3__();
 #endif
@@ -2830,7 +2830,7 @@
 
 allowTenureOf:anObject
     "set the age of anObject back to 0 so it may eventually tenure
-     into old space. 
+     into old space.
      This should only be used in very special situations.
      One such situation may be to ensure that an object is finalized early by the next
      scavenge, and not by a (possibly late) old space collect.
@@ -2838,12 +2838,12 @@
      any value with the seatAgeOf:to: message.
      If the object is already old, this call has no effect.
      WARNING: this method is for ST/X experts only
-              it is dangerous, should be used with care
-              and it may be removed without notice"
+	      it is dangerous, should be used with care
+	      and it may be removed without notice"
 
 
     self setAgeOf:anObject to:0
-    
+
     "
     |p|
     p := Point new.
@@ -3544,7 +3544,7 @@
 !
 
 preventTenureOf:anObject
-    "set the age of anObject to the never-tenure special age. 
+    "set the age of anObject to the never-tenure special age.
      This prevents the object from ever going out of the new space,
      and if used without care may lead to a filling of th newspace to a point,
      where the system becomes inoperable.
@@ -3555,14 +3555,14 @@
      any value with the seatAgeOf:to: message.
      If the object is already old, this call has no effect.
      WARNING: this method is for ST/X experts only
-              it is dangerous, should be used with care
-              and it may be removed without notice"
+	      it is dangerous, should be used with care
+	      and it may be removed without notice"
 
 %{  /* NOCONTEXT */
 #ifndef __SCHTEAM__
     if (__isNonNilObject(anObject)) {
-        _SET_AGE(anObject, NO_TENURE_AGE);
-    }    
+	_SET_AGE(anObject, NO_TENURE_AGE);
+    }
 #endif
 %}
     "
@@ -3587,21 +3587,21 @@
 !
 
 setAgeOf:anObject to:newAge
-    "change the age of anObject. 
+    "change the age of anObject.
      This counts the number of scavenges that an object has survived in new space.
      For old space objects, this is a no-op.
      WARNING: this method is for ST/X debugging only
-              it may be removed without notice"
+	      it may be removed without notice"
 
 %{  /* NOCONTEXT */
 #ifndef __SCHTEAM__
     if (__isNonNilObject(anObject) && __isSmallInteger(newAge)) {
-        int age = __intVal(newAge);
-
-        if (age < 0) age = 0;
-        else if (age > AGE_MAX) age = AGE_MAX;
-        _SET_AGE(anObject, age);
-    }    
+	int age = __intVal(newAge);
+
+	if (age < 0) age = 0;
+	else if (age > AGE_MAX) age = AGE_MAX;
+	_SET_AGE(anObject, age);
+    }
 #endif
 %}
     "
@@ -5567,21 +5567,21 @@
 
     localName := self nameForChangesLocal.
     userPrefs := UserPreferences current.
-    
+
     "/ if the prefs provide a full, explicit name
-    (nm := userPrefs changeFileName) isNil ifTrue:[ 
-
-        "/ if there is a workspace, create it there
-        ((wd := userPrefs workspaceDirectory) notNil and:[wd exists]) ifTrue:[
-            nm := wd / (localName asFilename baseName)
-        ] ifFalse:[
-            "/ if it was set by a startup file
-            (nm := ChangeFileName) isNil ifTrue:[
-                "/ finally, fall back to a default.
-                nm := localName
-            ]
-        ]
-    ].    
+    (nm := userPrefs changeFileName) isNil ifTrue:[
+
+	"/ if there is a workspace, create it there
+	((wd := userPrefs workspaceDirectory) notNil and:[wd exists]) ifTrue:[
+	    nm := wd / (localName asFilename baseName)
+	] ifFalse:[
+	    "/ if it was set by a startup file
+	    (nm := ChangeFileName) isNil ifTrue:[
+		"/ finally, fall back to a default.
+		nm := localName
+	    ]
+	]
+    ].
     ^ nm asFilename pathName.
 
     "
@@ -5631,10 +5631,10 @@
     |localName wd|
 
     localName := self nameForSnapshotLocal.
-    
+
     "/ if there is a workspace, create it there
     ((wd := UserPreferences current workspaceDirectory) notNil and:[wd exists]) ifTrue:[
-        ^ wd / (localName asFilename baseName)
+	^ wd / (localName asFilename baseName)
     ].
     ^ localName
 
@@ -5762,7 +5762,7 @@
      ST-80 compatibility; send #preSnapshot to all classes
     "
     Smalltalk allClassesDo:[:aClass |
-        aClass preSnapshot
+	aClass preSnapshot
     ].
 
     "
@@ -5772,55 +5772,55 @@
     "
     snapshotFilename := aFileName asFilename.
     snapshotFilename isAbsolute ifFalse:[
-        snapshotFilename := self directoryForImageAndChangeFile
-                            / snapshotFilename name.
+	snapshotFilename := self directoryForImageAndChangeFile
+			    / snapshotFilename name.
     ].
 
     tempFilename := (FileStream newTemporaryIn:snapshotFilename directory)
-                        close;
-                        fileName.
+			close;
+			fileName.
     ok := self primSnapShotOn:tempFilename.
 
     ok ifTrue:[
-        "keep history of one snapshot file"
-        snapshotFilename exists ifTrue:[
-            tempFilename symbolicAccessRights:snapshotFilename symbolicAccessRights.
-            snapshotFilename renameTo:(snapshotFilename withSuffix:'sav').
-        ] ifFalse:[
-            "image file hat stx as interpreter and can be executed"
-            tempFilename makeExecutable.
-        ].
-        tempFilename renameTo:snapshotFilename.
-
-        Class addChangeRecordForSnapshot:aFileName.
-
-        setImageName ifTrue:[
-            oldChangeFile := self nameForChanges.
-            ImageName := snapshotFilename asAbsoluteFilename asString.
-            self refreshChangesFrom:oldChangeFile.
-        ].
+	"keep history of one snapshot file"
+	snapshotFilename exists ifTrue:[
+	    tempFilename symbolicAccessRights:snapshotFilename symbolicAccessRights.
+	    snapshotFilename renameTo:(snapshotFilename withSuffix:'sav').
+	] ifFalse:[
+	    "image file hat stx as interpreter and can be executed"
+	    tempFilename makeExecutable.
+	].
+	tempFilename renameTo:snapshotFilename.
+
+	Class addChangeRecordForSnapshot:aFileName.
+
+	setImageName ifTrue:[
+	    oldChangeFile := self nameForChanges.
+	    ImageName := snapshotFilename asAbsoluteFilename asString.
+	    self refreshChangesFrom:oldChangeFile.
+	].
     ] ifFalse:[
-        tempFilename remove.
+	tempFilename remove.
     ].
 
     "
      ST-80 compatibility; send #postSnapshot to all classes
     "
     Smalltalk allClassesDo:[:aClass |
-        aClass postSnapshot
+	aClass postSnapshot
     ].
     self changed:#finishedSnapshot.  "/ ST-80 compatibility
 
     ok ifFalse:[
-        SnapshotError raise.
-        "not reached"
+	SnapshotError raise.
+	"not reached"
     ].
 
     Transcript
-        show:'Snapshot '; show:snapshotFilename baseName allBold;
-        show:' saved '; show:Timestamp now;
-        show:' in '; show:snapshotFilename asAbsoluteFilename directoryName;
-        showCR:'.'.
+	show:'Snapshot '; show:snapshotFilename baseName allBold;
+	show:' saved '; show:Timestamp now;
+	show:' in '; show:snapshotFilename asAbsoluteFilename directoryName;
+	showCR:'.'.
 
     ^ ok