ObjMem.st
author claus
Sun, 05 Feb 1995 22:32:46 +0100
changeset 229 210ee6865aa3
parent 216 a8abff749575
child 253 30daee717a53
permissions -rw-r--r--
commenting
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     1
"
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
     2
 COPYRIGHT (c) 1992 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
     3
	      All Rights Reserved
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
     4
a27a279701f8 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
a27a279701f8 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
a27a279701f8 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
a27a279701f8 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
a27a279701f8 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
a27a279701f8 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
a27a279701f8 Initial revision
claus
parents:
diff changeset
    11
"
a27a279701f8 Initial revision
claus
parents:
diff changeset
    12
a27a279701f8 Initial revision
claus
parents:
diff changeset
    13
Object subclass:#ObjectMemory
a27a279701f8 Initial revision
claus
parents:
diff changeset
    14
       instanceVariableNames:''
2
claus
parents: 1
diff changeset
    15
       classVariableNames:'InternalErrorHandler UserInterruptHandler TimerInterruptHandler
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    16
			   SpyInterruptHandler StepInterruptHandler ExceptionInterruptHandler
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    17
			   ErrorInterruptHandler MemoryInterruptHandler SignalInterruptHandler
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    18
			   ChildSignalInterruptHandler DisposeInterruptHandler
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    19
			   RecursionInterruptHandler IOInterruptHandler
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    20
			   CustomInterruptHandler
2
claus
parents: 1
diff changeset
    21
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
    22
			   AllocationFailureSignal LowSpaceSemaphore
207
claus
parents: 202
diff changeset
    23
			   IncrementalGCLimit BackgroundCollectProcess
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    24
			   Dependents
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    25
			   ImageName'
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    26
       poolDictionaries:''
a27a279701f8 Initial revision
claus
parents:
diff changeset
    27
       category:'System-Support'
a27a279701f8 Initial revision
claus
parents:
diff changeset
    28
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
    29
a27a279701f8 Initial revision
claus
parents:
diff changeset
    30
ObjectMemory comment:'
5
67342904af11 *** empty log message ***
claus
parents: 3
diff changeset
    31
COPYRIGHT (c) 1992 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    32
	     All Rights Reserved
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
    33
229
210ee6865aa3 commenting
claus
parents: 216
diff changeset
    34
$Header: /cvs/stx/stx/libbasic/Attic/ObjMem.st,v 1.23 1995-02-05 21:31:51 claus Exp $
2
claus
parents: 1
diff changeset
    35
'!
claus
parents: 1
diff changeset
    36
claus
parents: 1
diff changeset
    37
!ObjectMemory class methodsFor:'documentation'!
claus
parents: 1
diff changeset
    38
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    39
copyright
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    40
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    41
 COPYRIGHT (c) 1992 by Claus Gittinger
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    42
	      All Rights Reserved
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    43
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    44
 This software is furnished under a license and may be used
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    45
 only in accordance with the terms of that license and with the
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    46
 inclusion of the above copyright notice.   This software may not
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    47
 be provided or otherwise made available to, or used by, any
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    48
 other person.  No title to or ownership of the software is
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    49
 hereby transferred.
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    50
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    51
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    52
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    53
version
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    54
"
229
210ee6865aa3 commenting
claus
parents: 216
diff changeset
    55
$Header: /cvs/stx/stx/libbasic/Attic/ObjMem.st,v 1.23 1995-02-05 21:31:51 claus Exp $
88
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    56
"
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    57
!
81dacba7a63a *** empty log message ***
claus
parents: 85
diff changeset
    58
2
claus
parents: 1
diff changeset
    59
documentation
claus
parents: 1
diff changeset
    60
"
68
59faa75185ba *** empty log message ***
claus
parents: 56
diff changeset
    61
    This class contains access methods to the system memory -
59faa75185ba *** empty log message ***
claus
parents: 56
diff changeset
    62
    in previous versions this stuff used to be in the Smalltalk class.
59faa75185ba *** empty log message ***
claus
parents: 56
diff changeset
    63
    It has been separated for better overall structure.
229
210ee6865aa3 commenting
claus
parents: 216
diff changeset
    64
    There are no instances of ObjectMemory - all is done in class methods.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
    65
68
59faa75185ba *** empty log message ***
claus
parents: 56
diff changeset
    66
    Many methods here are for debuging purposes only, and not standard.
59faa75185ba *** empty log message ***
claus
parents: 56
diff changeset
    67
    Do not depend on them being there - some may vanish ...
59faa75185ba *** empty log message ***
claus
parents: 56
diff changeset
    68
    (especially those, that depend on a specific GC implementation)
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
    69
229
210ee6865aa3 commenting
claus
parents: 216
diff changeset
    70
    Warning:
210ee6865aa3 commenting
claus
parents: 216
diff changeset
    71
      The InterruptHandler variables are known by the runtime system -
210ee6865aa3 commenting
claus
parents: 216
diff changeset
    72
      they are the objects that get an interrupt message when the event
210ee6865aa3 commenting
claus
parents: 216
diff changeset
    73
      occurs. You may not remove them.
2
claus
parents: 1
diff changeset
    74
229
210ee6865aa3 commenting
claus
parents: 216
diff changeset
    75
    Class variables:
2
claus
parents: 1
diff changeset
    76
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    77
	InternalErrorHandler            gets informed (by VM), when some runtime
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    78
					error occurs (usually fatal)
2
claus
parents: 1
diff changeset
    79
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    80
	UserInterruptHandler            gets informed (by VM) when CNTL-C is pressed
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    81
	TimerInterruptHandler           gets alarm timer interrupts (from VM)
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    82
	SpyInterruptHandler             another alarm timer (from VM)
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    83
	StepInterruptHandler            gets single step interrupts (from VM)
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    84
	ExceptionInterruptHandler       gets floating point exceptions (from VM)
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    85
	ErrorInterruptHandler           gets graphic device errors (from VM)
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    86
	MemoryInterruptHandler          gets soon-out-of-memory conditions (from VM)
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    87
	SignalInterruptHandler          gets unix signals (from VM)
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    88
	ChildSignalInterruptHandler     gets child death signals (from VM)
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    89
	DisposeInterruptHandler         gets informed, when an object is disposed from 
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    90
					a shadowArray (from VM)
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    91
	RecursionInterruptHandler       gets recursion limit violations (from VM)
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    92
	IOInterruptHandler              gets SIGIO unix signals (from VM)
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    93
	CustomInterruptHandler          gets custom interrupts (from VM)
2
claus
parents: 1
diff changeset
    94
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    95
	IngrementalGCLimit              number of bytes, that must be allocated since
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    96
					last full garbage collect to turn on incremental
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    97
					collector.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    98
	Dependents                      keep my dependents locally (its faster) for
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
    99
					all those registries
213
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   100
	LowSpaceSemaphore               a semaphore signalled whenever the system is
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   101
					running in low memory (i.e. the memory manager
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   102
					ran into memory shortage and feels that it
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   103
					may soon be no longer grant allocation requests).
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   104
					You can have a process waiting on this semaphore
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   105
					which starts to remove (i.e. nil-out) objects
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   106
					or preform other cleanup actions.
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   107
                                        
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   108
	AllocationFailureSignal         signal raised when a new fails (see Behavior)
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   109
					When this signal is raised, the meomory manager
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   110
					is really in trouble (i.e. above feelings where
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   111
					correct)
2
claus
parents: 1
diff changeset
   112
"
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   113
!
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   114
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   115
caching
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   116
"
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   117
    The system uses various caches to speed up method-lookup.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   118
    Currently, there is a three-level cache hierarchy:
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   119
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   120
	inline-cache            keeps the target of the last send at the caller-
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   121
				side (i.e. every send goes through its private 
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   122
				1-slot inline-cache, where the address of the last
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   123
				called function at this call location is kept.)
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   124
229
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   125
	polymorph-inline-cache  keeps a limited list of all targets ever reached 
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   126
				at this call location. The list is automatically 
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   127
				flushed if it grows too large, or the overall number
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   128
				of poly-chache entries exceeds a limit.
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   129
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   130
	method-lookup-cache     a global cache. Hashes on class-selector pairs,
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   131
				returning the target method.
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   132
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   133
    Whenever methods are added or removed from the system, or the inheritance 
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   134
    hierarchy changes, some or all caches have to be flushed.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   135
    The flushXXX methods perform the task of flushing various caches.
207
claus
parents: 202
diff changeset
   136
    All standard methods in Behavior call for cache flushing, when things change;
229
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   137
    however, if you use the low level access methods in Behavior
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   138
    (for example: #setSuperclass:) special care has to be taken.
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   139
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   140
    In some situations, not all caches need flushing, for example a change
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   141
    in an interpreted method (currently) needs no flushing of the inline caches.
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   142
    Also, flushing can be limited to entries for a specific class for most changes.
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   143
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   144
    To be 'on the brigth side of live', use ObjectMemory>>flushCaches (which
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   145
    flushes all of them), when in doubt of which caches should be flushed. 
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   146
    It is better flush too much - otherwise you may end up in a wrong method after 
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   147
    a send.
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   148
"
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   149
!
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   150
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   151
interrupts
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   152
"
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   153
    Handling of interrupts (i.e. unix-signals) is done via handler objects, which
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   154
    get a #XXXInterrupt-message sent. This is more flexible than (say) signalling
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   155
    a semaphore, since the handler-object may do anything to react on the signal
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   156
    (of course, it can also signal a semaphore to emulate the above behavior).
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   157
229
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   158
    Another reason for having handler objects is that they allow interrupt handling
207
claus
parents: 202
diff changeset
   159
    without any context switch, for high speed interrupt response.
claus
parents: 202
diff changeset
   160
    However, special care is needed, since it is not defined, which process gets
claus
parents: 202
diff changeset
   161
    the interrupt and will do the processing.
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   162
    Typically, the handlers are set during early initialization of the system
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   163
    by sending 'ObjectMemory XXXInterruptHandler:aHandler' and not changed later.
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   164
    (see Smalltalk>>initialize or ProcessorScheduler>>initialize).
207
claus
parents: 202
diff changeset
   165
    To setup your own handler, create some object which responds to #xxxInterrupt,
claus
parents: 202
diff changeset
   166
    and make it the handler using the above method.
claus
parents: 202
diff changeset
   167
claus
parents: 202
diff changeset
   168
    Interrupt messages sent to handlers are:
claus
parents: 202
diff changeset
   169
	internalError:<someString>      - internal interpreter/GC errors
claus
parents: 202
diff changeset
   170
	userInterrupt                   - ^C interrupt
claus
parents: 202
diff changeset
   171
	customInterrupt                 - custom interrupt
claus
parents: 202
diff changeset
   172
	ioInterrupt                     - SIGIO interrupt
229
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   173
	timerInterrupt                  - alarm timer (SIGALRM)
207
claus
parents: 202
diff changeset
   174
	errorInterrupt                  - display error
229
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   175
	spyInterrupt                    - spy timer interrupt (SIGVTALARM)
207
claus
parents: 202
diff changeset
   176
	stepInterrupt                   - single step interrupt
claus
parents: 202
diff changeset
   177
	disposeInterrupt                - finalization required
claus
parents: 202
diff changeset
   178
	recursionInterrupt              - recursion (stack) overflow
claus
parents: 202
diff changeset
   179
	memoryInterrupt                 - soon running out of memory
229
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   180
	fpExceptionInterrupt            - floating point exception (SIGFPE)
207
claus
parents: 202
diff changeset
   181
	childSignalInterrupt            - death of a child process (SIGCHILD)
claus
parents: 202
diff changeset
   182
	signalInterrupt:<number>        - unix signal (if other than above signals)
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   183
"
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   184
!
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   185
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   186
garbageCollection
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   187
"
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   188
    Currently, Smalltalk/X uses a two-level memory hierachy.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   189
    Objects are created in a so-called newSpace, which is relatively small.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   190
    This newSpace is cleaned by a scavenge-operation, whenever becoming
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
   191
    full. Scavenging means, that all still-live objects (i.e. referenced by some 
433d44af1630 more GC control
claus
parents: 93
diff changeset
   192
    other) are copied over to another memory area, leaving all unreferenced
207
claus
parents: 202
diff changeset
   193
    objects as garbage behind. After this copying, these two semispaces exchange their
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   194
    roles - i.e. objects are copied ping-pong like between these semispaces.
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   195
    Once an object survives enough of these copying operations, the next scavenge 
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   196
    will move it into the so called oldSpace, which is much larger, and not
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   197
    processed by the scavenger. 
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   198
    This movement of an object from newSpace to oldSpace is called 'tenure'.
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
   199
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   200
    Scavenging occurs automatically, and is usually done fast enough to go 
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   201
    unnoticed (typically, it takes some 5 to 50ms to perform a scavenge, 
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   202
    depending on how many live objects are in the newspace).
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   203
    Interrestingly, the scavenger performs better, if many garbage objects
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   204
    are to be reclaimed, since less object-copying has to be done. Therefore,
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   205
    the best-case scavenge time is almost zero, if there is only garbage in
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   206
    the newSpace. In contrast, the worst-case is when all newSpace objects are still
207
claus
parents: 202
diff changeset
   207
    living. To honor this situation, the system uses an adaptive tenure-count,
claus
parents: 202
diff changeset
   208
    which adjusts the number of scavenges required for tenure (the so called 
claus
parents: 202
diff changeset
   209
    'tenureAge') according to the fill-grade of the newSpace.
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   210
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   211
    To reclaim oldspace, the system uses three algorithms: mark&sweep, a copying
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   212
    (and compressing) baker-type collector and an incremental mark&sweep.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   213
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   214
    The mark&sweep runs whenever the oldspace becomes full, putting dead objects
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   215
    onto a free list. If a memory request cannot be served from this freelist,
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   216
    and the total size of objects on the freelist exceeds a threshold, the system
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   217
    will compress the oldspace to make the free-space into one big area.
207
claus
parents: 202
diff changeset
   218
    This compress is done by copying all live objects into a newly allocated
claus
parents: 202
diff changeset
   219
    area, and freeing the previous memory afterwards (baker collector).
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   220
    Since a compressing oldspace collect leads to a noticable pause of the system,
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   221
    the memory manager tries hard to avoid oldspace compression.
207
claus
parents: 202
diff changeset
   222
    (actually, if enough real memory is available to hold both spaces in physical
claus
parents: 202
diff changeset
   223
     memory, the compress is pretty fast).
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   224
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   225
    The incremental mark&sweep runs in the background, whenever the system is idle
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   226
    (see ProcessorSceduler>>waitForEventOrTimeout). Like the normal mark&sweep,
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   227
    this incremental collector follows object references and marks reachable objects
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   228
    on its way. This is done 'a few objects-at-a-time', to not disrupt the system
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   229
    noticable. Incremental collection is controlled by the variable 
207
claus
parents: 202
diff changeset
   230
    'IncrementalGCLimit': the ProcessorScheduler will perform incremental GC steps
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
   231
    if the total space used by objects allocated since the last full collect exceeds 
433d44af1630 more GC control
claus
parents: 93
diff changeset
   232
    this number. Its default is set in ObjectMemory>>initialize and can be changed in
213
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   233
    your startup 'smalltalk.rc'-file. 
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   234
    Setting it to nil will turn incremental GC off.
207
claus
parents: 202
diff changeset
   235
    For example, setting this limit to 500000 will start the background collector
claus
parents: 202
diff changeset
   236
    whenever 500k bytes have been allocated - usually very seldom. Setting it to some
claus
parents: 202
diff changeset
   237
    small number (say 10000) will have it run very often.
213
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   238
    Setting it to a small number (i.e. running it often) should not hurt the
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   239
    performance of your other smalltalk processes, since the IGC only runs at
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   240
    idle times. (there are some delays in event processing, since the IGC's steps
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   241
    may take up to some 100ms.) However, if you are not alone on your machine
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   242
    (i.e. a timesharing system) or you have other Unix processes to run, you
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   243
    should not run the IGCLimit too often, since it may hurt other users.
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   244
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   245
    Since this collector only runs at idle times, even a low priority background 
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   246
    process will prevent it from doing its work. You may want to start a somewhat
207
claus
parents: 202
diff changeset
   247
    higher priority background collect (say at prio 4), which also preempts these
claus
parents: 202
diff changeset
   248
    background processes. (see ObjectMemory>>startBackgroundCollectorAt:).
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   249
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   250
    Beginning with 2.10.4, a third space, called fixSpace has been added.
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   251
    Objects in this space are never moved or garbage collected.
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   252
    This space is currently used for (some) symbols only, but additional constant
229
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   253
    objects may be put into it in the future (true, false, some basic classes etc.).
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   254
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   255
    A plan for 2.11 is to offer an arbitrary number of spaces, which can be
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   256
    attached and detached at runtime. This will allow easy share of object
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   257
    with remote systems and separating objects into a per application/package
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   258
    space. (be prepared for changes in the future and make your application
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   259
    independ of the VM internals)
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   260
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   261
  hints & tricks:
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   262
213
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   263
    normally, there is no need to call for an explicit garbage collection, or
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   264
    modify the default parameters.
213
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   265
    The memory system should adapt reasonable and provide good performance 
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   266
    for a wide range of allocation patterns (see Example3 below for an exception).
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   267
207
claus
parents: 202
diff changeset
   268
    However, there may be situations, in which hints and/or explicit
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   269
    control over allocation can speedup your programs; but please:
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   270
207
claus
parents: 202
diff changeset
   271
      - if you think you have to play around with the memory policies,
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   272
	first check your program - you may find useless allocations
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   273
	or bad uses of collections. A typical error that is made is to
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   274
	create large collections using the #, (comma) concatenation method,
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   275
	which shows square behavior, since it allocates many, many temporary
213
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   276
	collections. Also, watch out for #copyWith:, #add: etc.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   277
	All of these create a new collection. Remember, that most collections
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   278
	offer methods to preallocate some space; for example, 'Set new:' creates
229
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   279
	an empty set, but preallocates space to avoid resizing over and over.
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   280
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   281
	An especially bad performace dog is to use #add: on fix-size collection
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   282
	objects (such as Strings or Arrays), since in addition to allocating
229
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   283
	lots of garbage, a #become: operation is required for EACH element
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   284
	added. NEVER use Arrays for growing/shrinking data - use OrderedCollection
229
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   285
	instead. (if you really need an array, use asArray afterwards)
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   286
207
claus
parents: 202
diff changeset
   287
      - if you are going to allocate huge data structures, think about
claus
parents: 202
diff changeset
   288
	optimizing space. For example, if you allocate a million instances of
213
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   289
	some object, each added instance variable makes up 4Mb of additional 
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   290
	memory need.
207
claus
parents: 202
diff changeset
   291
	Also, for Byte-valued, Integer-valued and Float like objects, special
claus
parents: 202
diff changeset
   292
	collections are provided, which store their values directly inside (instead
claus
parents: 202
diff changeset
   293
	of a reference to the object). A FloatArray consisting of 1 million floats
213
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   294
	requires about 4mb of memory, while an Array of Floats requires 4mb for the
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
   295
	references to the floats, PLUS 20Mb for the floats themself.
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   296
207
claus
parents: 202
diff changeset
   297
      - check if you really need fast access to all of these objects; you may
claus
parents: 202
diff changeset
   298
	try to only keep some subset in memory, and use binary storage or
claus
parents: 202
diff changeset
   299
	(if this is too slow) optimized store/retrieve methods and keep the bigger
229
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   300
	part in a file. 
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   301
	(How about a DiskArray class, which does this transparent ?
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   302
	 See the FileText class for some ideas and something to start with ...)
207
claus
parents: 202
diff changeset
   303
claus
parents: 202
diff changeset
   304
claus
parents: 202
diff changeset
   305
    Hint / Example 1: 
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   306
      you are about to allocate a huge data structure, which is known to
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   307
      survive long. In this case, it is better to have these objects move into the
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   308
      oldspace sooner, to avoid the copying overhead during scavenges.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   309
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   310
      To do this, you can call ObjectMemory>>tenure after allocation, which
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   311
      forces all new-objects immediately into the oldspace. 
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   312
      Make certain, that not to many (ideally no) short-living objects are in the
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   313
      newspace when doing this.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   314
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   315
      Another alternative is to tell the system that all allocation should be
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   316
      done directly in the oldspace. This completely avoids the scavenging overhead
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   317
      for these objects. To do so, use ObjectMemory>>turnGarbageCollectorOff
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   318
      before the allocation, and ObjectMemory>>turnGarbageCollectorOn afterwards.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   319
      Keep in mind, that do-loops may allocate block-objects and other temporaries,
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   320
      so there is a danger of making things worse due to having all those temporaries
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   321
      in the oldspace afterwards. (which is not a fatal situation, but will
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   322
      force the system to do an oldspace collect earlier, which may not be your
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   323
      intention).
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   324
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   325
207
claus
parents: 202
diff changeset
   326
   Hint / Example 2:
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   327
      you know in advance, that a certain (big) amount of memory will be needed.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   328
      For example, the fileBrowser wants to show a huge file in its text-view.
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
   329
      In this case, it is better to tell the memory system in advance, how much
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   330
      memory will be needed, since otherwise many compresses and reallocations will
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
   331
      occur (the memory system will allocate additional memory in chunks of smaller
433d44af1630 more GC control
claus
parents: 93
diff changeset
   332
      256k pieces, if a compress failes. Thus, if you are going to allocate (say) 1Mb of 
433d44af1630 more GC control
claus
parents: 93
diff changeset
   333
      strings, it will perform 5 compressing GC's).
433d44af1630 more GC control
claus
parents: 93
diff changeset
   334
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   335
      This is done using ObjectMemory>>moreOldSpace: or ObjectMemory announceSpaceNeed:.
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   336
      In the above example, you would do 'ObjectMemory announceSpaceNeed:500000', which 
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
   337
      avoids those annoying 5 compressing GC's.
207
claus
parents: 202
diff changeset
   338
      BTW: if you have other smalltalk processes (threads) running which should not be
claus
parents: 202
diff changeset
   339
      paused if possible, it is better to use #announceSpaceNeed. This tries to avoid 
claus
parents: 202
diff changeset
   340
      pausing in other processes and sometimes succeeds, while moreOldSpace will always 
claus
parents: 202
diff changeset
   341
      block the whole system for a while. However, there is no 'no-pause' guarantee.
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
   342
433d44af1630 more GC control
claus
parents: 93
diff changeset
   343
      The amount of automatic increase (in case the oldSpace becomes full) is 256k by
433d44af1630 more GC control
claus
parents: 93
diff changeset
   344
      default. This number can be changed with ObjectMemory>>oldSpaceIncrement:.
433d44af1630 more GC control
claus
parents: 93
diff changeset
   345
207
claus
parents: 202
diff changeset
   346
claus
parents: 202
diff changeset
   347
    Hint / Example3:
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   348
      There are rare cases, when an explicit GC makes a difference: since
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   349
      object finalization is done at GC time, objects which keep operatingSystem
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   350
      resources may be finalized late. This is normally no problem, except if
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   351
      the system is running out of resources. For example, allocating new colors
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   352
      may fail if many colors have already been allocated in the past - even
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   353
      though these colors are actually free. The Depth8Image calls for an
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   354
      explicit GC, whenever it fails to allocate a color for a bitmap, to force
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   355
      finalization of free, but not yet finalized colors.
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   356
207
claus
parents: 202
diff changeset
   357
claus
parents: 202
diff changeset
   358
    Hint 4:
claus
parents: 202
diff changeset
   359
      If you run in too small of physical memory, the incremental GC may have a
claus
parents: 202
diff changeset
   360
      bad effect on your working set: since it touches pages (which may otherwise
claus
parents: 202
diff changeset
   361
      not be needed at the moment, the operating system is forced to steal other
claus
parents: 202
diff changeset
   362
      (possibly more useful) pages from your set of incore pages.
claus
parents: 202
diff changeset
   363
      You may get better performance, if you turn off the incremental GC while
claus
parents: 202
diff changeset
   364
      processing a big data structure.
claus
parents: 202
diff changeset
   365
claus
parents: 202
diff changeset
   366
229
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   367
    Warning: many of the methods found here are not standard and may not even be available in
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
   368
    future versions of ST/X. Use them only in very special situations or experiments.
229
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   369
207
claus
parents: 202
diff changeset
   370
    Let me know about additional special features you think are useful, and about
claus
parents: 202
diff changeset
   371
    special features you are using - this provides the feedback required to decide
claus
parents: 202
diff changeset
   372
    which methods are to be removed or kept or enhanced in future versions.
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   373
"
2
claus
parents: 1
diff changeset
   374
! !
claus
parents: 1
diff changeset
   375
claus
parents: 1
diff changeset
   376
!ObjectMemory class methodsFor:'initialization'!
claus
parents: 1
diff changeset
   377
claus
parents: 1
diff changeset
   378
initialize
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   379
    "initialize the class"
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   380
2
claus
parents: 1
diff changeset
   381
    AllocationFailureSignal isNil ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   382
	Object initialize.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   383
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   384
	AllocationFailureSignal := Object errorSignal newSignalMayProceed:true.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   385
	AllocationFailureSignal nameClass:self message:#allocationFailureSignal.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   386
	AllocationFailureSignal notifierString:'allocation failure'.
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   387
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   388
	LowSpaceSemaphore := Semaphore new.
2
claus
parents: 1
diff changeset
   389
    ].
claus
parents: 1
diff changeset
   390
    IncrementalGCLimit := 500000.
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   391
    MemoryInterruptHandler := self
2
claus
parents: 1
diff changeset
   392
! !
claus
parents: 1
diff changeset
   393
claus
parents: 1
diff changeset
   394
!ObjectMemory class methodsFor:'signal access'!
claus
parents: 1
diff changeset
   395
claus
parents: 1
diff changeset
   396
allocationFailureSignal
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   397
    "return the signal raised when an object allocation failed"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   398
2
claus
parents: 1
diff changeset
   399
    ^ AllocationFailureSignal
claus
parents: 1
diff changeset
   400
! !
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   401
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   402
!ObjectMemory class methodsFor:'semaphore access'!
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   403
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   404
lowSpaceSemaphore
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   405
    "return the semaphore that is signalled when the system detects a
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   406
     low space condition. Usually, some time after this, an allocationFailure
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   407
     will happen. You can have a cleanup process sitting in that semaphore and
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   408
     start to release object."
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   409
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   410
    ^ LowSpaceSemaphore
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   411
! !
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   412
10
claus
parents: 5
diff changeset
   413
!ObjectMemory class methodsFor:'dependents access'!
claus
parents: 5
diff changeset
   414
claus
parents: 5
diff changeset
   415
dependents
claus
parents: 5
diff changeset
   416
    "return the colleciton of my dependents"
claus
parents: 5
diff changeset
   417
claus
parents: 5
diff changeset
   418
    ^ Dependents
claus
parents: 5
diff changeset
   419
!
claus
parents: 5
diff changeset
   420
claus
parents: 5
diff changeset
   421
dependents:aCollection
claus
parents: 5
diff changeset
   422
    "set the dependents collection"
claus
parents: 5
diff changeset
   423
claus
parents: 5
diff changeset
   424
    Dependents := aCollection
claus
parents: 5
diff changeset
   425
! !
claus
parents: 5
diff changeset
   426
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   427
!ObjectMemory class methodsFor:'cache management'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   428
a27a279701f8 Initial revision
claus
parents:
diff changeset
   429
flushInlineCachesForClass:aClass
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   430
    "flush inlinecaches for calls to aClass."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   431
a27a279701f8 Initial revision
claus
parents:
diff changeset
   432
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   433
    __flushInlineCachesFor(aClass);
a27a279701f8 Initial revision
claus
parents:
diff changeset
   434
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
   435
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   436
a27a279701f8 Initial revision
claus
parents:
diff changeset
   437
flushInlineCachesWithArgs:nargs
a27a279701f8 Initial revision
claus
parents:
diff changeset
   438
    "flush inlinecaches for calls with nargs arguments"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   439
a27a279701f8 Initial revision
claus
parents:
diff changeset
   440
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   441
    __flushInlineCaches(_intVal(nargs));
a27a279701f8 Initial revision
claus
parents:
diff changeset
   442
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
   443
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   444
a27a279701f8 Initial revision
claus
parents:
diff changeset
   445
flushInlineCachesFor:aClass withArgs:nargs
a27a279701f8 Initial revision
claus
parents:
diff changeset
   446
    "flush inlinecaches for calls to aClass with nargs arguments"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   447
a27a279701f8 Initial revision
claus
parents:
diff changeset
   448
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   449
    __flushInlineCachesForAndNargs(aClass, _intVal(nargs));
a27a279701f8 Initial revision
claus
parents:
diff changeset
   450
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
   451
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   452
a27a279701f8 Initial revision
claus
parents:
diff changeset
   453
flushInlineCaches
a27a279701f8 Initial revision
claus
parents:
diff changeset
   454
    "flush all inlinecaches"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   455
a27a279701f8 Initial revision
claus
parents:
diff changeset
   456
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   457
    __flushAllInlineCaches();
a27a279701f8 Initial revision
claus
parents:
diff changeset
   458
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
   459
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   460
a27a279701f8 Initial revision
claus
parents:
diff changeset
   461
flushMethodCacheFor:aClass
a27a279701f8 Initial revision
claus
parents:
diff changeset
   462
    "flush the method cache for sends to aClass"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   463
a27a279701f8 Initial revision
claus
parents:
diff changeset
   464
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   465
    __flushMethodCacheFor(aClass);
a27a279701f8 Initial revision
claus
parents:
diff changeset
   466
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
   467
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   468
a27a279701f8 Initial revision
claus
parents:
diff changeset
   469
flushMethodCache
a27a279701f8 Initial revision
claus
parents:
diff changeset
   470
    "flush the method cache"
a27a279701f8 Initial revision
claus
parents:
diff changeset
   471
a27a279701f8 Initial revision
claus
parents:
diff changeset
   472
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   473
    __flushMethodCache();
a27a279701f8 Initial revision
claus
parents:
diff changeset
   474
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
   475
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   476
2
claus
parents: 1
diff changeset
   477
flushCachesFor:aClass
claus
parents: 1
diff changeset
   478
    "flush method and inline caches for aClass"
claus
parents: 1
diff changeset
   479
claus
parents: 1
diff changeset
   480
%{  /* NOCONTEXT */
claus
parents: 1
diff changeset
   481
    __flushMethodCacheFor(aClass);
claus
parents: 1
diff changeset
   482
    __flushInlineCachesFor(aClass);
claus
parents: 1
diff changeset
   483
%}
claus
parents: 1
diff changeset
   484
!
claus
parents: 1
diff changeset
   485
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   486
flushCaches
2
claus
parents: 1
diff changeset
   487
    "flush method and inline caches for all classes"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   488
a27a279701f8 Initial revision
claus
parents:
diff changeset
   489
%{  /* NOCONTEXT */
a27a279701f8 Initial revision
claus
parents:
diff changeset
   490
    __flushMethodCache();
a27a279701f8 Initial revision
claus
parents:
diff changeset
   491
    __flushAllInlineCaches();
a27a279701f8 Initial revision
claus
parents:
diff changeset
   492
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
   493
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   494
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   495
!ObjectMemory class methodsFor:'enumerating'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   496
a27a279701f8 Initial revision
claus
parents:
diff changeset
   497
allObjectsDo:aBlock
85
claus
parents: 77
diff changeset
   498
    "evaluate the argument, aBlock for all objects in the system.
claus
parents: 77
diff changeset
   499
     There is one caveat: if a compressing oldSpace collect
claus
parents: 77
diff changeset
   500
     occurs while looping over the objects, the loop cannot be
claus
parents: 77
diff changeset
   501
     continued (for some internal reasons). In this case, false
claus
parents: 77
diff changeset
   502
     is returned."
2
claus
parents: 1
diff changeset
   503
claus
parents: 1
diff changeset
   504
    |work|
22
847106305963 *** empty log message ***
claus
parents: 13
diff changeset
   505
847106305963 *** empty log message ***
claus
parents: 13
diff changeset
   506
%{  /* NOREGISTER - work may not be placed into a register here */
2
claus
parents: 1
diff changeset
   507
    nonTenuringScavenge(__context);
claus
parents: 1
diff changeset
   508
    /*
claus
parents: 1
diff changeset
   509
     * allObjectsDo needs a temporary to hold newSpace objects
claus
parents: 1
diff changeset
   510
     */
85
claus
parents: 77
diff changeset
   511
    if (__allObjectsDo(&aBlock, &work COMMA_CON) < 0) {
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   512
	RETURN (false);
85
claus
parents: 77
diff changeset
   513
    }
claus
parents: 77
diff changeset
   514
%}.
claus
parents: 77
diff changeset
   515
    ^ true
2
claus
parents: 1
diff changeset
   516
!
claus
parents: 1
diff changeset
   517
claus
parents: 1
diff changeset
   518
allOldObjectsDo:aBlock
claus
parents: 1
diff changeset
   519
    "evaluate the argument, aBlock for all old objects in the system.
claus
parents: 1
diff changeset
   520
     For debugging and tests only - do not use"
claus
parents: 1
diff changeset
   521
%{
85
claus
parents: 77
diff changeset
   522
    if (__allObjectsDo(&aBlock, (OBJ *)0 COMMA_CON) < 0) {
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   523
	RETURN (false);
85
claus
parents: 77
diff changeset
   524
    }
claus
parents: 77
diff changeset
   525
%}. 
claus
parents: 77
diff changeset
   526
    ^ true
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   527
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
   528
229
210ee6865aa3 commenting
claus
parents: 216
diff changeset
   529
!ObjectMemory class methodsFor:'interrupt handler access'!
2
claus
parents: 1
diff changeset
   530
claus
parents: 1
diff changeset
   531
internalErrorHandler
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   532
    "return the handler for ST/X internal errors.
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   533
     An internal error is reported for example when a methods
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   534
     bytecode is not a ByteArray, the selector table is not an Array
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   535
     etc.  
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   536
     Those should not occur in normal circumstances."
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   537
2
claus
parents: 1
diff changeset
   538
    ^ InternalErrorHandler
claus
parents: 1
diff changeset
   539
!
claus
parents: 1
diff changeset
   540
claus
parents: 1
diff changeset
   541
userInterruptHandler
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   542
    "return the handler for CNTL-C interrupt handling"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   543
2
claus
parents: 1
diff changeset
   544
    ^ UserInterruptHandler
claus
parents: 1
diff changeset
   545
!
claus
parents: 1
diff changeset
   546
claus
parents: 1
diff changeset
   547
userInterruptHandler:aHandler
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   548
    "set the handler for CNTL-C interrupt handling"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   549
2
claus
parents: 1
diff changeset
   550
    UserInterruptHandler := aHandler
claus
parents: 1
diff changeset
   551
!
claus
parents: 1
diff changeset
   552
claus
parents: 1
diff changeset
   553
timerInterruptHandler
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   554
    "return the handler for timer interrupts"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   555
2
claus
parents: 1
diff changeset
   556
    ^ TimerInterruptHandler
claus
parents: 1
diff changeset
   557
!
claus
parents: 1
diff changeset
   558
10
claus
parents: 5
diff changeset
   559
timerInterruptHandler:aHandler
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   560
    "set the handler for timer interrupts"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   561
10
claus
parents: 5
diff changeset
   562
    TimerInterruptHandler := aHandler
claus
parents: 5
diff changeset
   563
!
claus
parents: 5
diff changeset
   564
2
claus
parents: 1
diff changeset
   565
spyInterruptHandler
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   566
    "return the handler for spy-timer interrupts"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   567
2
claus
parents: 1
diff changeset
   568
    ^ SpyInterruptHandler
claus
parents: 1
diff changeset
   569
!
claus
parents: 1
diff changeset
   570
claus
parents: 1
diff changeset
   571
spyInterruptHandler:aHandler
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   572
    "set the handler for spy-timer interrupts"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   573
2
claus
parents: 1
diff changeset
   574
    SpyInterruptHandler := aHandler
claus
parents: 1
diff changeset
   575
!
claus
parents: 1
diff changeset
   576
claus
parents: 1
diff changeset
   577
stepInterruptHandler
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   578
    "return the handler for single step interrupts"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   579
2
claus
parents: 1
diff changeset
   580
    ^ StepInterruptHandler
claus
parents: 1
diff changeset
   581
!
claus
parents: 1
diff changeset
   582
claus
parents: 1
diff changeset
   583
stepInterruptHandler:aHandler
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   584
    "set the handler for single step interrupts"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   585
2
claus
parents: 1
diff changeset
   586
    StepInterruptHandler := aHandler
claus
parents: 1
diff changeset
   587
!
claus
parents: 1
diff changeset
   588
claus
parents: 1
diff changeset
   589
exceptionInterruptHandler
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   590
    "return the handler for floating point exception interrupts"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   591
2
claus
parents: 1
diff changeset
   592
    ^ ExceptionInterruptHandler
claus
parents: 1
diff changeset
   593
!
claus
parents: 1
diff changeset
   594
claus
parents: 1
diff changeset
   595
errorInterruptHandler
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   596
    "return the handler for display error interrupts"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   597
2
claus
parents: 1
diff changeset
   598
    ^ ErrorInterruptHandler
claus
parents: 1
diff changeset
   599
!
claus
parents: 1
diff changeset
   600
claus
parents: 1
diff changeset
   601
errorInterruptHandler:aHandler
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   602
    "set the handler for display error interrupts"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   603
2
claus
parents: 1
diff changeset
   604
    ErrorInterruptHandler := aHandler
claus
parents: 1
diff changeset
   605
!
claus
parents: 1
diff changeset
   606
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   607
signalInterruptHandler
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   608
    "return the handler for UNIX-signal interrupts"
2
claus
parents: 1
diff changeset
   609
claus
parents: 1
diff changeset
   610
    ^ SignalInterruptHandler
claus
parents: 1
diff changeset
   611
!
claus
parents: 1
diff changeset
   612
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   613
signalInterruptHandler:aHandler
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   614
    "set the handler for UNIX-signal interrupts"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   615
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   616
    SignalInterruptHandler := aHandler
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   617
!
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   618
2
claus
parents: 1
diff changeset
   619
childSignalInterruptHandler
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   620
    "return the handler for UNIX-death-of-a-childprocess-signal interrupts"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   621
2
claus
parents: 1
diff changeset
   622
    ^ ChildSignalInterruptHandler
claus
parents: 1
diff changeset
   623
!
claus
parents: 1
diff changeset
   624
claus
parents: 1
diff changeset
   625
disposeInterruptHandler
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   626
    "return the handler for object disposal interrupts"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   627
2
claus
parents: 1
diff changeset
   628
    ^ DisposeInterruptHandler
claus
parents: 1
diff changeset
   629
!
claus
parents: 1
diff changeset
   630
claus
parents: 1
diff changeset
   631
disposeInterruptHandler:aHandler
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   632
    "set the handler for object disposal interrupts"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   633
2
claus
parents: 1
diff changeset
   634
    DisposeInterruptHandler := aHandler
claus
parents: 1
diff changeset
   635
!
claus
parents: 1
diff changeset
   636
claus
parents: 1
diff changeset
   637
recursionInterruptHandler
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   638
    "return the handler for recursion/stack overflow interrupts"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   639
2
claus
parents: 1
diff changeset
   640
    ^ RecursionInterruptHandler
claus
parents: 1
diff changeset
   641
!
claus
parents: 1
diff changeset
   642
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   643
recursionInterruptHandler:aHandler
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   644
    "set the handler for recursion/stack overflow interrupts"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   645
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   646
    RecursionInterruptHandler := aHandler
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   647
!
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   648
2
claus
parents: 1
diff changeset
   649
ioInterruptHandler
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   650
    "return the handler for I/O available signal interrupts (SIGIO/SIGPOLL)"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   651
2
claus
parents: 1
diff changeset
   652
    ^ IOInterruptHandler
claus
parents: 1
diff changeset
   653
!
claus
parents: 1
diff changeset
   654
claus
parents: 1
diff changeset
   655
ioInterruptHandler:aHandler
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   656
    "set the handler for I/O available signal interrupts (SIGIO/SIGPOLL)"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   657
2
claus
parents: 1
diff changeset
   658
    IOInterruptHandler := aHandler
85
claus
parents: 77
diff changeset
   659
!
claus
parents: 77
diff changeset
   660
claus
parents: 77
diff changeset
   661
customInterruptHandler
claus
parents: 77
diff changeset
   662
    "return the handler for custom interrupts"
claus
parents: 77
diff changeset
   663
claus
parents: 77
diff changeset
   664
    ^ CustomInterruptHandler
claus
parents: 77
diff changeset
   665
!
claus
parents: 77
diff changeset
   666
claus
parents: 77
diff changeset
   667
customInterruptHandler:aHandler
claus
parents: 77
diff changeset
   668
    "set the handler for custom interrupts"
claus
parents: 77
diff changeset
   669
claus
parents: 77
diff changeset
   670
    CustomInterruptHandler := aHandler
2
claus
parents: 1
diff changeset
   671
! !
claus
parents: 1
diff changeset
   672
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   673
!ObjectMemory class methodsFor:'queries'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   674
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   675
newSpaceSize
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   676
    "return the total size of the new space - this is usually fix"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   677
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   678
%{  /* NOCONTEXT */
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
   679
    extern unsigned __newSpaceSize();
433d44af1630 more GC control
claus
parents: 93
diff changeset
   680
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   681
    RETURN ( _MKSMALLINT(__newSpaceSize()) );
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   682
%}
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   683
    "
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   684
     ObjectMemory newSpaceSize
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   685
    "
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   686
!
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   687
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   688
oldSpaceSize
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   689
    "return the total size of the old space. - may grow slowly"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   690
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   691
%{  /* NOCONTEXT */
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
   692
    extern unsigned __oldSpaceSize();
433d44af1630 more GC control
claus
parents: 93
diff changeset
   693
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   694
    RETURN ( _MKSMALLINT(__oldSpaceSize()) );
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   695
%}
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   696
    "
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   697
     ObjectMemory oldSpaceSize
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   698
    "
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   699
!
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   700
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   701
fixSpaceSize
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   702
    "return the total size of the fix space."
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   703
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   704
%{  /* NOCONTEXT */
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   705
    extern unsigned __fixSpaceSize();
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   706
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   707
    RETURN ( _MKSMALLINT(__fixSpaceSize()) );
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   708
%}
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   709
    "
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   710
     ObjectMemory fixSpaceSize
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   711
    "
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   712
!
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   713
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   714
newSpaceUsed
10
claus
parents: 5
diff changeset
   715
    "return the number of bytes allocated for new objects.
claus
parents: 5
diff changeset
   716
     The returned value is usually obsolete as soon as you do
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   717
     something with it ..."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   718
a27a279701f8 Initial revision
claus
parents:
diff changeset
   719
%{  /* NOCONTEXT */
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
   720
    extern unsigned __newSpaceUsed();
433d44af1630 more GC control
claus
parents: 93
diff changeset
   721
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   722
    RETURN ( _MKSMALLINT(__newSpaceUsed()) );
a27a279701f8 Initial revision
claus
parents:
diff changeset
   723
%}
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   724
    "
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   725
     ObjectMemory newSpaceUsed   
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   726
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   727
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   728
a27a279701f8 Initial revision
claus
parents:
diff changeset
   729
oldSpaceUsed
10
claus
parents: 5
diff changeset
   730
    "return the number of bytes allocated for old objects.
claus
parents: 5
diff changeset
   731
     (This includes the free lists)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   732
a27a279701f8 Initial revision
claus
parents:
diff changeset
   733
%{  /* NOCONTEXT */
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
   734
    extern unsigned __oldSpaceUsed();
433d44af1630 more GC control
claus
parents: 93
diff changeset
   735
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   736
    RETURN ( _MKSMALLINT(__oldSpaceUsed()) );
a27a279701f8 Initial revision
claus
parents:
diff changeset
   737
%}
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   738
    "
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   739
     ObjectMemory oldSpaceUsed  
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   740
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   741
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   742
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   743
fixSpaceUsed
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   744
    "return the number of bytes allocated for old objects in fix space."
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   745
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   746
%{  /* NOCONTEXT */
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   747
    extern unsigned __fixSpaceUsed();
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   748
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   749
    RETURN ( _MKSMALLINT(__fixSpaceUsed()) );
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   750
%}
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   751
    "
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   752
     ObjectMemory fixSpaceUsed
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   753
    "
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   754
!
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
   755
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
   756
freeListSpace
10
claus
parents: 5
diff changeset
   757
    "return the number of bytes in the free lists.
claus
parents: 5
diff changeset
   758
     (which is included in oldSpaceUsed)"
claus
parents: 5
diff changeset
   759
claus
parents: 5
diff changeset
   760
%{  /* NOCONTEXT */
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
   761
    extern unsigned __freeListSpace();
433d44af1630 more GC control
claus
parents: 93
diff changeset
   762
433d44af1630 more GC control
claus
parents: 93
diff changeset
   763
    RETURN ( _MKSMALLINT(__freeListSpace()) );
10
claus
parents: 5
diff changeset
   764
%}
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   765
    "
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
   766
     ObjectMemory freeListSpace
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   767
    "
10
claus
parents: 5
diff changeset
   768
!
claus
parents: 5
diff changeset
   769
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   770
bytesUsed
a27a279701f8 Initial revision
claus
parents:
diff changeset
   771
    "return the number of bytes allocated for objects -
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   772
     this number is not exact, since some objects may already be dead
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   773
     (i.e. not yet reclaimed by the garbage collector).
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   774
     If you need the exact number, you have to loop over all
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   775
     objects and ask for the bytesize using ObjectMemory>>sizeOf:."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   776
a27a279701f8 Initial revision
claus
parents:
diff changeset
   777
%{  /* NOCONTEXT */
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
   778
    extern unsigned __oldSpaceUsed(), __newSpaceUsed(), __freeListSpace();
433d44af1630 more GC control
claus
parents: 93
diff changeset
   779
433d44af1630 more GC control
claus
parents: 93
diff changeset
   780
    RETURN ( _MKSMALLINT(__oldSpaceUsed() + __newSpaceUsed() - __freeListSpace()) );
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   781
%}
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   782
    "
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   783
     ObjectMemory bytesUsed  
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   784
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   785
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   786
2
claus
parents: 1
diff changeset
   787
oldSpaceAllocatedSinceLastGC
claus
parents: 1
diff changeset
   788
    "return the number of bytes allocated for old objects since the
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   789
     last oldspace garbage collect occured. This information is used
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   790
     by ProcessorScheduler to decide when to start the incremental
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   791
     background GC."
2
claus
parents: 1
diff changeset
   792
claus
parents: 1
diff changeset
   793
%{  /* NOCONTEXT */
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
   794
    extern unsigned __oldSpaceAllocatedSinceLastGC();
433d44af1630 more GC control
claus
parents: 93
diff changeset
   795
2
claus
parents: 1
diff changeset
   796
    RETURN ( _MKSMALLINT(__oldSpaceAllocatedSinceLastGC()) );
claus
parents: 1
diff changeset
   797
%}
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   798
    "
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   799
     ObjectMemory oldSpaceAllocatedSinceLastGC   
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   800
    "
2
claus
parents: 1
diff changeset
   801
!
claus
parents: 1
diff changeset
   802
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   803
tenureAge
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   804
    "return the current tenure age - thats the number of times
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   805
     an object has to survive scavenges to be moved into oldSpace.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   806
     For statistic/debugging only - this method may vanish"
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   807
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   808
%{  /* NOCONTEXT */
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   809
    extern unsigned __tenureAge();
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   810
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   811
    RETURN ( _MKSMALLINT(__tenureAge()) );
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   812
%}
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   813
!
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   814
194
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
   815
lastScavangeReclamation
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
   816
    "returns the number of bytes replacimed by the last scavenge.
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
   817
     For statistic only - this may vanish."
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
   818
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
   819
%{  /* NOCONTEXT */
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
   820
    extern int __newSpaceReclaimed();
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
   821
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
   822
    RETURN ( _MKSMALLINT(__newSpaceReclaimed()) );
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
   823
%}
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   824
    "percentage of reclaimed objects is returned by:
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   825
194
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
   826
     ((ObjectMemory lastScavangeReclamation)
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   827
      / (ObjectMemory newSpaceSize)) * 100.0  
194
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
   828
    "
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
   829
!
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
   830
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   831
runsSingleOldSpace
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   832
    "return true, if the system runs in a single oldSpace or
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   833
     false, if it has given up baker-collection. The memory
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   834
     system will always drop the second semispace when running out of
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   835
     virtual memory, or the baker-limit is reached.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   836
     OBSOLETE: 
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   837
	 the system may now decide at any time to switch between
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   838
	 single and double-space algorithms, depending on the overall memory
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   839
	 size. You will now almost always get false as result, since the
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   840
	 second semispaces are only allocated when needed, and released
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   841
	 afterwards.
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   842
    "
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   843
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   844
%{  /* NOCONTEXT */
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   845
    extern char *collectedOldStartPtr;
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   846
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   847
    RETURN ( ((collectedOldStartPtr == (char *)0) ? true : false) );
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   848
%}
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   849
    "
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   850
     ObjectMemory runsSingleOldSpace 
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   851
    "
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   852
!
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   853
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   854
incrementalGCPhase
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   855
    "returns the internal state of the incremental GC.
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   856
     The meaning of those numbers is a secret :-).
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   857
     This is for debugging and monitoring only - and may vanish"
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   858
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   859
%{  /* NOCONTEXT */
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   860
    extern int __incrGCphase();
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   861
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   862
    RETURN (_MKSMALLINT(__incrGCphase()));
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   863
%}
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   864
!
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   865
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   866
numberOfObjects
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   867
    "return the number of objects in the system."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   868
a27a279701f8 Initial revision
claus
parents:
diff changeset
   869
    |tally|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   870
a27a279701f8 Initial revision
claus
parents:
diff changeset
   871
    tally := 0.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   872
    self allObjectsDo:[:obj | tally := tally + 1].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   873
    ^ tally
a27a279701f8 Initial revision
claus
parents:
diff changeset
   874
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   875
    "
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   876
     ObjectMemory numberOfObjects  
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
   877
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   878
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   879
a27a279701f8 Initial revision
claus
parents:
diff changeset
   880
printReferences:anObject
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
   881
    "for debugging: print referents to anObject.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   882
     WARNING: 
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   883
	this method will vanish; 
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   884
	use ObjectMemory>>whoReferences: or anObject>>allOwners."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   885
a27a279701f8 Initial revision
claus
parents:
diff changeset
   886
%{
a27a279701f8 Initial revision
claus
parents:
diff changeset
   887
    _printRefChain(__context, anObject);
a27a279701f8 Initial revision
claus
parents:
diff changeset
   888
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
   889
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
   890
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   891
collectObjectsWhich:aBlock
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   892
    "helper for the whoReferences queries. Returns a collection
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   893
     of objects for which aBlock returns true."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   894
a27a279701f8 Initial revision
claus
parents:
diff changeset
   895
    |aCollection|
a27a279701f8 Initial revision
claus
parents:
diff changeset
   896
a27a279701f8 Initial revision
claus
parents:
diff changeset
   897
    aCollection := IdentitySet new.
a27a279701f8 Initial revision
claus
parents:
diff changeset
   898
    self allObjectsDo:[:o |
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   899
	(aBlock value:o) ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   900
	    aCollection add:o
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   901
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   902
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   903
    (aCollection size == 0) ifTrue:[
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   904
	"actually this cannot happen - there is always one"
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   905
	^ nil
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
   906
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
   907
    ^ aCollection
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   908
!
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   909
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   910
whoReferences:anObject
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   911
    "return a collection of objects referencing the argument, anObject"
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   912
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   913
    ^ self collectObjectsWhich:[:o | o references:anObject]
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   914
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   915
    "
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   916
     (ObjectMemory whoReferences:Transcript) printNL
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   917
    "
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   918
!
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   919
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   920
whoReferencesInstancesOf:aClass
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   921
    "return a collection of objects refering to instances
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   922
     of the argument, aClass"
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   923
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   924
    ^ self collectObjectsWhich:[:o | o referencesInstanceOf:aClass]
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   925
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   926
    "
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   927
     (ObjectMemory whoReferencesInstancesOf:SystemBrowser) printNL
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   928
    "
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   929
!
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   930
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   931
whoReferencesDerivedInstancesOf:aClass
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   932
    "return a collection of objects refering to instances
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   933
     of the argument, aClass or a subclass of it."
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   934
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   935
    ^ self collectObjectsWhich:[:o | o referencesDerivedInstanceOf:aClass]
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   936
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   937
    "
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   938
     (ObjectMemory whoReferencesDerivedInstancesOf:View) printNL
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   939
    "
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   940
!
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   941
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   942
addressOf:anObject
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   943
    "return the core address of anObject as an integer
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   944
     - since objects may move around, the returned value is invalid after the
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   945
     next scavenge/collect.
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   946
     Use only for debugging."
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   947
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   948
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   949
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   950
    if (! _isNonNilObject(anObject)) {
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   951
	RETURN ( nil );
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   952
    }
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   953
    RETURN ( _MKSMALLINT( (int)anObject ) );
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   954
%}
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   955
    "
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   956
    |p|
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   957
    p := Point new.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   958
    (ObjectMemory addressOf:p) printNL.
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   959
    ObjectMemory scavenge.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
   960
    (ObjectMemory addressOf:p) printNL.
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   961
    "
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   962
!
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   963
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   964
objectAt:anAddress
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   965
    "return whatever anAddress points to as object.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   966
     BIG BIG DANGER ALERT: 
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   967
	this method is only to be used for debugging
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
   968
	ST/X itself - you can easily (and badly) crash the system.
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   969
     This method will be removed from the final shipping version"
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   970
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   971
    |low high|
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   972
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   973
    low := anAddress bitAnd:16rFFFF.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   974
    high := (anAddress bitShift:16) bitAnd:16rFFFF.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   975
%{
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   976
    if (_isSmallInteger(low)
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   977
     && _isSmallInteger(high)) {
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   978
	RETURN ((OBJ)((_intVal(high) << 16) | _intVal(low)));
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   979
    }
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   980
%}
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   981
!
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   982
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   983
sizeOf:anObject
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   984
    "return the size of anObject in bytes.
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   985
     Use only for debugging/memory monitoring."
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   986
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   987
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   988
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   989
    RETURN ( _isNonNilObject(anObject) ? _MKSMALLINT(_qSize(anObject)) : _MKSMALLINT(0) )
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   990
%}
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   991
    "
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   992
     |hist big nw|
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   993
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   994
     hist := Array new:100 withAll:0.
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   995
     big := 0.
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
   996
     ObjectMemory allObjectsDo:[:o |
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   997
	 nw := (ObjectMemory sizeOf:o) // 4 + 1.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   998
	 nw > 100 ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
   999
	    big := big + 1
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1000
	 ] ifFalse:[
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1001
	    hist at:nw put:(hist at:nw) + 1
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1002
	 ].
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1003
     ].
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1004
     hist printNL.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1005
     big printNL
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1006
    "
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1007
!
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1008
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1009
spaceOf:anObject
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1010
    "return the memory space, in which anObject is.
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1011
     - since objects may move between spaces, returned value is invalid after the
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1012
     next scavenge/collect.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1013
     For debugging only; Dont use this method; it may vanish."
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1014
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1015
%{  /* NOCONTEXT */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1016
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1017
    if (! _isNonNilObject(anObject)) {
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1018
	RETURN ( nil );
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1019
    }
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1020
    RETURN ( _MKSMALLINT( _qSpace(anObject) ) );
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1021
%}
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1022
!
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1023
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1024
flagsOf:anObject
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1025
    "For debugging only; Dont use this method; it may vanish."
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1026
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1027
%{  /* NOCONTEXT */
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1028
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1029
    if (! _isNonNilObject(anObject)) {
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1030
	RETURN ( nil );
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1031
    }
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1032
    RETURN ( _MKSMALLINT( anObject->o_flags ) );
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1033
%}
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1034
    "
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1035
F_ISREMEMBERED  1       /* a new-space thing being refd by some oldSpace thing */
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1036
F_ISFORWARDED   2       /* a forwarded object (you will never see this here) */
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1037
F_DEREFERENCED  4       /* a collection after grow (not currently used) */
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1038
F_ISONLIFOLIST  8       /* a non-lifo-context-referencing-obj already on list */
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1039
F_MARK          16      /* mark bit for background collector */
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1040
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1041
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1042
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1043
ageOf:anObject
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1044
    "return the number of scavenges, an object has survived
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1045
     in new space. For old objects and living contexts, the returned number 
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1046
     is invalid.
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1047
     For debugging only; Dont use this method; it may vanish."
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1048
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1049
%{  /* NOCONTEXT */
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1050
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1051
    if (! _isNonNilObject(anObject)) {
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1052
	RETURN ( 0 );
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1053
    }
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1054
    RETURN ( _MKSMALLINT( _GET_AGE(anObject) ) );
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1055
%}
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1056
    "
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1057
    |p|
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1058
    p := Point new.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1059
    (ObjectMemory ageOf:p) printNL.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1060
    ObjectMemory tenuringScavenge.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1061
    (ObjectMemory spaceOf:p) printNL.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1062
    ObjectMemory tenuringScavenge.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1063
    (ObjectMemory spaceOf:p) printNL.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1064
    ObjectMemory tenuringScavenge.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1065
    (ObjectMemory spaceOf:p) printNL.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1066
    ObjectMemory tenuringScavenge.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1067
    (ObjectMemory spaceOf:p) printNL.
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1068
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1069
! !
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1070
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1071
!ObjectMemory class methodsFor:'garbage collection'!
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1072
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1073
scavenge
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1074
    "collect young objects, without aging (i.e. no tenure).
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1075
     Can be used to quickly get rid of shortly before allocated
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1076
     stuff. This is relatively fast (compared to oldspace collect).
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1077
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1078
     An example where a non-tenuring scavenge makes sense is when
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1079
     allocating some OperatingSystem resource (a Color, File or View) 
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1080
     and the OS runs out of resources. In this case, the scavenge may
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1081
     free some ST-objects and therefore (by signalling the WeakArrays
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1082
     or Registries) free the OS resources too.
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1083
     Of course, only recently allocated resources will be freed this
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1084
     way. If none was freed, a full collect will be needed."
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1085
%{
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1086
    nonTenuringScavenge(__context);
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1087
%}
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1088
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1089
    "
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1090
     ObjectMemory scavenge
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1091
    "
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1092
!
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1093
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1094
tenuringScavenge
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1095
    "collect newspace stuff, with aging (i.e. objects old enough
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1096
     will be moved into the oldSpace).
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1097
     Use this for debugging and testing only - the system performs
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1098
     this automatically when the newspace fills up.
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1099
     This is relatively fast (compared to oldspace collect)"
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1100
%{
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1101
    scavenge(__context);
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1102
%}
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1103
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1104
    "
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1105
     ObjectMemory tenuringScavenge
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1106
    "
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1107
!
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1108
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1109
tenure
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1110
    "force all living new stuff into old-space - effectively making
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1111
     all living young objects become old objects.
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1112
     This is relatively fast (compared to oldspace collect).
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1113
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1114
     This method should only be used in very special situations:
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1115
     for example, when building up some long-living data structure
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1116
     in a time critical application.
194
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1117
     To do so, you have to do a scavenge followed by a tenure after the
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1118
     objects are created. Be careful, to not reference any other chunk-
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1119
     data when calling for a tenure (this will lead to lots of garbage in
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1120
     the oldspace).
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1121
     In normal situations, explicit tenures are not needed."
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1122
%{
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1123
    tenure(__context);
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1124
%}
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1125
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1126
    "
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1127
     ObjectMemory tenure
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1128
    "
194
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1129
    "
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1130
     ... build up long living objects ...
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1131
     ObjectMemory scavenge.
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1132
     ObjectMemory tenure
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1133
     ... continue - objects created above are now in oldSpace ...
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1134
    "
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1135
!
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1136
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1137
garbageCollect
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1138
    "search for and free garbage in the oldSpace (newSpace is cleaned automatically) 
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1139
     performing a COMPRESSING garbage collect.
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1140
     This can take a long time - especially, if paging is involved
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1141
     (when no paging is involved, its faster than I thought :-).
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1142
     If no memory is available for the compress, or the system has been started with
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1143
     the -Msingle option, this does a non-COMPRESSING collect."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1144
%{
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1145
    if (! __garbageCollect(__context)) {
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1146
	markAndSweep(__context);
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1147
    }
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1148
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1149
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1150
    "
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1151
     ObjectMemory garbageCollect
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1152
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1153
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1154
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1155
reclaimSymbols
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1156
    "reclaim unused symbols;
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1157
     Unused symbols are (currently) not reclaimed automatically,
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1158
     but only upon request with this method. It takes some time
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1159
     to do this ...
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1160
     Future versions may do this automatically, while garbage collecting."
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1161
%{
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1162
    __reclaimSymbols(__context);
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1163
%}
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1164
    "
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1165
     ObjectMemory reclaimSymbols
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1166
    "
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1167
!
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1168
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1169
markAndSweep
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1170
    "mark/sweep garbage collector.
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1171
     perform a full mark&sweep collect.
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1172
     Warning: this may take some time."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1173
%{
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1174
    markAndSweep(__context);
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1175
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1176
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1177
    "
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1178
     ObjectMemory markAndSweep
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1179
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1180
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1181
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1182
gcStep
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1183
    "one incremental garbage collect step.
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1184
     Mark or sweep some small number of objects. This
85
claus
parents: 77
diff changeset
  1185
     method will return after a reasonable (short) time.
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1186
     This is used by the ProcessorScheduler at idle times.
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1187
     Returns true, if an incremental GC cycle has finished."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1188
%{
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1189
    extern int __incrGCstep();
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1190
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1191
    RETURN (__incrGCstep(__context) ? true : false);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1192
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1193
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1194
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1195
incrementalGC
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1196
    "perform one round of incremental GC steps.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1197
     The overall effect of this method is the same as calling markAndSweep.
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1198
     However, #incrementalGC is interruptable while #markAndSweep
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1199
     blocks for a while. Thus this method can be called from a low 
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1200
     prio (background) process to collect without disturbing 
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1201
     foreground processes too much.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1202
     For example, someone allocating huge amounts of memory could
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1203
     ask for the possibility of a quick allocation using
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1204
     #checkForFastNew: and try a #incrementalGC if not. In many
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1205
     cases, this can avoid a pause due to a blocking GC."
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1206
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1207
    [self gcStep] whileFalse:[]
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1208
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1209
    "
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1210
     ObjectMemory incrementalGC
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1211
    "
194
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1212
!
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1213
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1214
verboseGarbageCollect
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1215
    "perform a compessing garbage collect and show some informational
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1216
     output on the Transcript"
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1217
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1218
    |nBytesBefore nReclaimed|
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1219
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1220
    nBytesBefore := self oldSpaceUsed.
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1221
    self garbageCollect.
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1222
    nReclaimed := nBytesBefore - self oldSpaceUsed.
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1223
    nReclaimed > 0 ifTrue:[
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1224
	Transcript show:'reclaimed '.
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1225
	nReclaimed > 1024 ifTrue:[
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1226
	    nReclaimed > (1024 * 1024) ifTrue:[
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1227
		Transcript show:(nReclaimed // (1024 * 1024)) printString.
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1228
		Transcript showCr:' Mb.'
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1229
	    ] ifFalse:[
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1230
		Transcript show:(nReclaimed // 1024) printString.
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1231
		Transcript showCr:' Kb.'
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1232
	    ]
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1233
	] ifFalse:[
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1234
	    Transcript show:nReclaimed printString.
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1235
	    Transcript showCr:' bytes.'
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1236
	]
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1237
    ]
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1238
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1239
    "
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1240
     ObjectMemory verboseGarbageCollect
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1241
    "
207
claus
parents: 202
diff changeset
  1242
!
claus
parents: 202
diff changeset
  1243
claus
parents: 202
diff changeset
  1244
startBackgroundCollectorAt:aPriority
claus
parents: 202
diff changeset
  1245
    "start a process doing incremental GC in the background.
claus
parents: 202
diff changeset
  1246
     Use this, if you have suspendable background processes which
claus
parents: 202
diff changeset
  1247
     run all the time, and therefore would prevent the idle-collector
claus
parents: 202
diff changeset
  1248
     from running. See documentation in this class for more details."
claus
parents: 202
diff changeset
  1249
claus
parents: 202
diff changeset
  1250
    BackgroundCollectProcess notNil ifTrue:[
claus
parents: 202
diff changeset
  1251
	BackgroundCollectProcess priority:aPriority.
claus
parents: 202
diff changeset
  1252
	^ self
claus
parents: 202
diff changeset
  1253
    ].
claus
parents: 202
diff changeset
  1254
    BackgroundCollectProcess :=
claus
parents: 202
diff changeset
  1255
	[
211
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1256
	    [true] whileTrue:[
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1257
		IncrementalGCLimit notNil ifTrue:[
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1258
		    self oldSpaceAllocatedSinceLastGC > IncrementalGCLimit ifTrue:[
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1259
			"
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1260
			 start a cycle
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1261
			"
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1262
			self incrementalGC
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1263
		    ]
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1264
		].
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1265
		"
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1266
		 wait a bit
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1267
		"
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  1268
		(Delay forSeconds:5) wait
211
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1269
	    ]
207
claus
parents: 202
diff changeset
  1270
	] newProcess.
claus
parents: 202
diff changeset
  1271
    BackgroundCollectProcess name:'background collector'.
claus
parents: 202
diff changeset
  1272
    BackgroundCollectProcess priority:aPriority.
claus
parents: 202
diff changeset
  1273
    BackgroundCollectProcess resume
211
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1274
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1275
    "
216
a8abff749575 *** empty log message ***
claus
parents: 213
diff changeset
  1276
     ObjectMemory incrementalGCLimit:10000.
211
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1277
     ObjectMemory startBackgroundCollectorAt:5
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1278
    "
207
claus
parents: 202
diff changeset
  1279
!
claus
parents: 202
diff changeset
  1280
claus
parents: 202
diff changeset
  1281
stopBackgroundCollector
claus
parents: 202
diff changeset
  1282
    "stop the background collector"
claus
parents: 202
diff changeset
  1283
claus
parents: 202
diff changeset
  1284
    BackgroundCollectProcess notNil ifTrue:[
claus
parents: 202
diff changeset
  1285
	BackgroundCollectProcess terminate.
claus
parents: 202
diff changeset
  1286
	BackgroundCollectProcess := nil
claus
parents: 202
diff changeset
  1287
    ]
211
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1288
    "
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1289
     ObjectMemory stopBackgroundCollector
58bb873aa83c *** empty log message ***
claus
parents: 207
diff changeset
  1290
    "
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1291
! !
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1292
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1293
!ObjectMemory class methodsFor:'garbage collector control'!
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1294
2
claus
parents: 1
diff changeset
  1295
incrementalGCLimit:aNumber
85
claus
parents: 77
diff changeset
  1296
    "set the limit for incremental GC activation.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1297
     This is used by the ProcessorScheduler; it will start doing incremental
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1298
     background GC, once more than this number of bytes have been allocated since
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1299
     the last GC. The default is 500000; setting it to nil will turn incremental
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1300
     GC off."
2
claus
parents: 1
diff changeset
  1301
claus
parents: 1
diff changeset
  1302
    IncrementalGCLimit := aNumber
claus
parents: 1
diff changeset
  1303
85
claus
parents: 77
diff changeset
  1304
    "
213
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
  1305
     ObjectMemory incrementalGCLimit:500000.  'do incr. GC very seldom'
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
  1306
     ObjectMemory incrementalGCLimit:100000.  'medium'
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
  1307
     ObjectMemory incrementalGCLimit:10000.   'do incr. GC very often'
3b56a17534fd *** empty log message ***
claus
parents: 211
diff changeset
  1308
     ObjectMemory incrementalGCLimit:nil.     'never'
85
claus
parents: 77
diff changeset
  1309
    "
2
claus
parents: 1
diff changeset
  1310
!
claus
parents: 1
diff changeset
  1311
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1312
incrementalGCLimit
85
claus
parents: 77
diff changeset
  1313
    "return the limit for incremental GC activation.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1314
     This is used by the ProcessorScheduler; it will start doing incremental
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1315
     background GC, once more than this number of bytes have been allocated since
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1316
     the last GC. The default is 500000; setting it to nil will turn incremental
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1317
     GC off."
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1318
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1319
    ^ IncrementalGCLimit
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1320
85
claus
parents: 77
diff changeset
  1321
    "
claus
parents: 77
diff changeset
  1322
     ObjectMemory incrementalGCLimit
claus
parents: 77
diff changeset
  1323
    "
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1324
!
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1325
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1326
moreOldSpace:howMuch
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1327
    "allocate howMuch bytes more for old objects.
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1328
     This is done automatically, when running out of space, but makes
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1329
     sense, if its known in advance that a lot of memory is needed to
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1330
     avoid multiple reallocations and compresses.
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1331
     This (currently) implies a compressing garbage collect - so its slow.
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1332
     Notice: this is a nonstandard interface - use only in special situations."
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1333
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1334
%{  
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1335
    if (_isSmallInteger(howMuch))
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1336
	__moreOldSpace(__context, _intVal(howMuch));
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1337
%}
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1338
    "
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1339
     ObjectMemory moreOldSpace:1000000
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1340
    "
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1341
!
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1342
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1343
announceSpaceNeed:howMuch
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1344
    "announce to the memory system, that howMuch bytes of memory will be needed
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1345
     soon. The VM tries to prepare itself for this allocation to be performed
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1346
     with less overhead. For example, it could preallocate some memory in one
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1347
     big chunk (instead of doing many smaller reallocations later).
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1348
     Notice: this is a nonstandard interface - use only in special situations.
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1349
     Also, this does a background collect before the big chunk of memory is
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1350
     allocated, not locking other processes while doing so."
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1351
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1352
    (howMuch < (self newSpaceSize // 2)) ifTrue:[
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1353
	self scavenge.
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1354
    ].
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1355
    (self checkForFastNew:howMuch) ifFalse:[
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1356
	(howMuch > (self newSpaceSize // 2)) ifFalse:[
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1357
	    self scavenge.
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1358
	].
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1359
	self incrementalGC.
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1360
	(self checkForFastNew:howMuch) ifFalse:[
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1361
	    self moreOldSpace:howMuch
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1362
	]
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1363
    ]
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1364
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1365
    "
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1366
     ObjectMemory announceSpaceNeed:100000
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1367
    "
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1368
!
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1369
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1370
announceOldSpaceNeed:howMuch
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1371
    "announce to the memory system, that howMuch bytes of memory will be needed
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1372
     soon, which is going to live longer (whatever that means). 
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1373
     It first checks if the memory can be allocated without forcing a compressing
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1374
     GC. If not, the oldSpace is increased. This may also lead to a slow compressing
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1375
     collect. However, many smaller increases are avoided afterwards. Calling this
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1376
     method before allocating huge chunks of data may provide better overall performance.
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1377
     Notice: this is a nonstandard interface - use only in special situations."
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1378
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1379
    (self checkForFastNew:howMuch) ifFalse:[
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1380
	self incrementalGC.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1381
	(self checkForFastNew:howMuch) ifFalse:[
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1382
	    self moreOldSpace:howMuch
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1383
	]
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1384
    ]
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1385
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1386
    "
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1387
     ObjectMemory announceOldSpaceNeed:1000000
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1388
    "
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1389
!
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1390
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1391
oldSpaceIncrement
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1392
    "return the oldSpaceIncrement value. Thats the amount by which
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1393
     more memory is allocated in case the oldSpace gets filled up.
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1394
     In normal situations, the default value used in the VM is fine
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1395
     and there is no need to change it."
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1396
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1397
%{  /* NOCONTEXT */
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1398
    extern unsigned __oldSpaceIncrement();
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1399
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1400
    RETURN (_MKSMALLINT( __oldSpaceIncrement(-1) )); 
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1401
%}
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1402
    "
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1403
     ObjectMemory oldSpaceIncrement
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1404
    "
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1405
!
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1406
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1407
oldSpaceIncrement:amount
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1408
    "set the oldSpaceIncrement value. Thats the amount by which
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1409
     more memory is allocated in case the oldSpace gets filled up.
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1410
     In normal situations, the default value used in the VM is fine
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1411
     and there is no need to change it. This method returns the 
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1412
     previous increment value."
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1413
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1414
%{  /* NOCONTEXT */
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1415
    extern unsigned __oldSpaceIncrement();
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1416
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1417
    if (_isSmallInteger(amount)) {
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1418
	RETURN (_MKSMALLINT( __oldSpaceIncrement(_intVal(amount)) )); 
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1419
    }
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1420
%}
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1421
    "to change increment to 1Meg:"
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1422
    "
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1423
     ObjectMemory oldSpaceIncrement:1024*1024
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1424
    "
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1425
!
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1426
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1427
fastMoreOldSpaceAllocation:aBoolean
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1428
    "this method turns on/off fastMoreOldSpace allocation.
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1429
     By default, this is turned off (false), which means that in case of
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1430
     a filled-up oldSpace, a GC is tried first before more oldSpace is allocated. 
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1431
     This strategy is ok for the normal operation of the system,
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1432
     but behaves badly, if the program allocates huge data structures (say a
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1433
     game tree of 30Mb in size) which survives and therefore will not be reclaimed
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1434
     by a GC.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1435
     Of course while building this tree, and the memory becomes full, the system 
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1436
     would not know in advance, that the GC will not reclaim anything.
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1437
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1438
     Setting fastOldSpaceIncrement to true will avoid this, by forcing the
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1439
     memory system to allocate more memory right away, without doing a GC first.
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1440
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1441
     WARNING: make certain that this flag is turned off, after your huge data
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1442
     is allocated, since otherwise the system may continue to increase its
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1443
     virtual memory without ever checking for garbage.
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1444
     This method returns the previous value of the flag."
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1445
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1446
%{   /* NOCONTEXT */
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1447
     RETURN (__fastMoreOldSpaceAllocation(aBoolean == true ? 1 : 0) ? true : false);
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1448
%}
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1449
!
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1450
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1451
checkForFastNew:amount
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1452
    "this method returns true, if amount bytes could be allocated
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1453
     quickly (i.e. without forcing a full GC or compress).
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1454
     This can be used for smart background processes, which want to
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1455
     allocate big chunks of data without disturbing foreground processes
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1456
     too much. Such a process would check for fast-allocation, and perform
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1457
     incremental GC-steps if required. Thus, avoiding the long blocking pause 
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1458
     due to a forced (non-incremental) GC. Especially: doing so will not block
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1459
     higher priority foreground processes.
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1460
     This is experimental and not guaranteed to be in future versions."
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1461
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1462
%{  /* NOCONTEXT */
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1463
    extern __checkForFastNew();
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1464
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1465
    if (_isSmallInteger(amount)) {
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1466
	if (! __checkForFastNew(_intVal(amount))) {
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1467
	    RETURN (false);
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1468
	}
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1469
    }
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1470
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1471
%}.
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1472
    ^ true
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1473
!
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1474
2
claus
parents: 1
diff changeset
  1475
turnGarbageCollectorOff
claus
parents: 1
diff changeset
  1476
    "turn off garbage collector by forcing new objects to be
claus
parents: 1
diff changeset
  1477
     allocated in oldSpace (instead of newSpace)
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1478
     WARNING:
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1479
     This is somewhat dangerous: if collector is turned off,
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1480
     and too many objects are created, the system may run into trouble
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1481
     (i.e. oldSpace becomes full) and be forced to perform a full mark&sweep
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1482
     or even a compressing collect - making the overall realtime behavior worse.
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1483
     Use this only for special purposes or when realtime behavior
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1484
     is required for a limited time period."
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1485
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1486
%{  /* NOCONTEXT */
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1487
    __allocForceSpace(OLDSPACE);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1488
%}
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1489
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1490
2
claus
parents: 1
diff changeset
  1491
turnGarbageCollectorOn
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1492
    "turn garbage collector on again (see ObjectMemory>>turnGarbageCollectorOff)"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1493
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1494
%{  /* NOCONTEXT */
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1495
    __allocForceSpace(9999);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1496
%}
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1497
!
85
claus
parents: 77
diff changeset
  1498
claus
parents: 77
diff changeset
  1499
makeOld:anObject
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1500
    "move anObject into oldSpace.
133
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1501
     This method is for internal & debugging purposes only -
433d44af1630 more GC control
claus
parents: 93
diff changeset
  1502
     it may vanish. Dont use it."
85
claus
parents: 77
diff changeset
  1503
%{
claus
parents: 77
diff changeset
  1504
    if (__moveToOldSpace(anObject, __context) < 0) {
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1505
	RETURN (false);
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1506
    }
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1507
%}.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1508
    ^ true
194
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1509
!
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1510
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1511
tenureParameters:magic
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1512
    "this is pure magic and not for public eyes ...
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1513
     This method allows fine tuning the scavenger internals,
194
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1514
     in cooperation to some statistic & test programs.
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1515
     It is undocumented, secret and may vanish. 
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1516
     If you play around here, the system may behave very strange."
194
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1517
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1518
%{  /* NOCONTEXT */
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1519
    __tenureParams(magic);
197c209e61f4 fine tuning tenure
claus
parents: 178
diff changeset
  1520
%}.
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1521
! !
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1522
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1523
!ObjectMemory class methodsFor:'physical memory access'!
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1524
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1525
newSpacePagesDo:aBlock
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1526
    "evaluates aBlock for all pages in the newSpace, passing
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1527
     the pages address as argument.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1528
     For internal & debugging use only."
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1529
%{
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1530
    if (__newSpacePagesDo(&aBlock COMMA_CON) < 0) {
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1531
	RETURN (false);
85
claus
parents: 77
diff changeset
  1532
    }
claus
parents: 77
diff changeset
  1533
%}.
claus
parents: 77
diff changeset
  1534
    ^ true
claus
parents: 77
diff changeset
  1535
!
claus
parents: 77
diff changeset
  1536
claus
parents: 77
diff changeset
  1537
oldSpacePagesDo:aBlock
claus
parents: 77
diff changeset
  1538
    "evaluates aBlock for all pages in the oldSpace, passing
claus
parents: 77
diff changeset
  1539
     the pages address as argument. 
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1540
     For internal & debugging use only."
85
claus
parents: 77
diff changeset
  1541
%{
claus
parents: 77
diff changeset
  1542
    if (__oldSpacePagesDo(&aBlock COMMA_CON) < 0) {
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1543
	RETURN (false);
85
claus
parents: 77
diff changeset
  1544
    }
claus
parents: 77
diff changeset
  1545
%}.
claus
parents: 77
diff changeset
  1546
    ^ true
claus
parents: 77
diff changeset
  1547
!
claus
parents: 77
diff changeset
  1548
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1549
collectedOldSpacePagesDo:aBlock
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1550
    "evaluates aBlock for all pages in the prev. oldSpace, passing
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1551
     the pages address as argument. 
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1552
     For internal & debugging use only."
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1553
%{
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1554
    if (__collectedOldSpacePagesDo(&aBlock COMMA_CON) < 0) {
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1555
	RETURN (false);
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1556
    }
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1557
%}.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1558
    ^ true
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1559
!
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1560
85
claus
parents: 77
diff changeset
  1561
pageIsInCore:aPageNumber
claus
parents: 77
diff changeset
  1562
    "return true, if the page (as enumerated via oldSpacePagesDo:)
claus
parents: 77
diff changeset
  1563
     is in memory; false, if currently paged out. For internal
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1564
     use / monitors only; may vanish.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1565
     NOTICE: not all systems provide this information; on those that
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1566
     do not, true is returned for all pages."
85
claus
parents: 77
diff changeset
  1567
%{
claus
parents: 77
diff changeset
  1568
#ifdef HAS_MINCORE
claus
parents: 77
diff changeset
  1569
    int pageSize = getpagesize();
claus
parents: 77
diff changeset
  1570
    char result[10];
claus
parents: 77
diff changeset
  1571
    INT addr;
claus
parents: 77
diff changeset
  1572
claus
parents: 77
diff changeset
  1573
    if (_isSmallInteger(aPageNumber)) {
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1574
	addr = _intVal(aPageNumber) & ~(pageSize - 1);
85
claus
parents: 77
diff changeset
  1575
    } else {
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1576
	addr = ((INT)aPageNumber) & ~(pageSize - 1);
85
claus
parents: 77
diff changeset
  1577
    }
claus
parents: 77
diff changeset
  1578
    if (mincore(addr, pageSize-1, result) < 0) {
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1579
	RETURN (true);
85
claus
parents: 77
diff changeset
  1580
    }
claus
parents: 77
diff changeset
  1581
    RETURN ((result[0] & 1) ? true : false);
claus
parents: 77
diff changeset
  1582
#endif
claus
parents: 77
diff changeset
  1583
%}.
claus
parents: 77
diff changeset
  1584
    "OS does not supply this info - assume yes"
claus
parents: 77
diff changeset
  1585
    ^ true
claus
parents: 77
diff changeset
  1586
! !
claus
parents: 77
diff changeset
  1587
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1588
!ObjectMemory class methodsFor:'low memory handling'!
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1589
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1590
memoryInterrupt
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1591
    "when a low-memory condition arises, ask all classes to
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1592
     remove possibly cached data - this may help a bit"
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1593
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1594
    Smalltalk allBehaviors do:[:aClass |
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1595
	aClass lowSpaceCleanup
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1596
    ].
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1597
178
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1598
"/    self error:'almost out of memory'
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1599
    'almost out of memory' errorPrintNL.
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1600
4da1b10bf42c more GC control
claus
parents: 159
diff changeset
  1601
    LowSpaceSemaphore signalIf.
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1602
! !
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1603
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1604
!ObjectMemory class methodsFor:'system management'!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1605
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1606
loadClassBinary:aClassName
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1607
    "find the object file for aClassName and -if found - load it;
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1608
     this one loads precompiled object files"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1609
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1610
    |fName newClass upd|
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1611
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1612
    fName := self fileNameForClass:aClassName.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1613
    fName notNil ifTrue:[
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1614
	Class withoutUpdatingChangesDo:
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1615
	[
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1616
	    self loadBinary:(fName , '.o')
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1617
	].
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1618
	newClass := self at:(aClassName asSymbol).
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1619
	(newClass notNil and:[newClass implements:#initialize]) ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1620
	    newClass initialize
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1621
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1622
    ]
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1623
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1624
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1625
imageName
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1626
    "return the filename of the current image, or nil
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1627
     if not running from an image."
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1628
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1629
    ^ ImageName
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1630
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1631
    "
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1632
     ObjectMemory imageName 
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1633
    "
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1634
!
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1635
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1636
imageBaseName
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1637
    "return a reasonable filename to use as baseName (i.e. without extension).
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1638
     This is the filename of the current image (without '.img') or,
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1639
     if not running from an image, the default name 'st'"
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1640
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1641
    |nm|
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1642
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1643
    nm := ImageName.
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1644
    (nm isNil or:[nm isBlank]) ifTrue:[
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1645
	^ 'st'
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1646
    ].
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1647
    (nm endsWith:'.sav') ifTrue:[
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1648
	nm := nm copyTo:(nm size - 4)
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1649
    ].
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1650
    (nm endsWith:'.img') ifTrue:[
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1651
	^ nm copyTo:(nm size - 4)
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1652
    ].
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1653
    ^ nm
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1654
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1655
    "
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1656
     ObjectMemory imageBaseName    
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1657
    "
77
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1658
!
6c38ca59927f *** empty log message ***
claus
parents: 68
diff changeset
  1659
22
847106305963 *** empty log message ***
claus
parents: 13
diff changeset
  1660
nameForSnapshot
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1661
    "return a reasonable filename to store the snapshot image into.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1662
     This is the filename of the current image or,
22
847106305963 *** empty log message ***
claus
parents: 13
diff changeset
  1663
     if not running from an image, the default name 'st.img'"
847106305963 *** empty log message ***
claus
parents: 13
diff changeset
  1664
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1665
    ^ self imageBaseName , '.img'
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1666
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1667
    "
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1668
     ObjectMemory nameForSnapshot    
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1669
    "
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1670
!
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1671
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1672
nameForSources
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1673
    "return a reasonable filename to store the sources into.
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1674
     This is the basename of the current image with '.img' replaced
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1675
     by '.src', or, if not running from an image, the default name 'st.src'"
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1676
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1677
    ^ self imageBaseName , '.src'
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1678
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1679
    "
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1680
     ObjectMemory nameForSources    
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1681
    "
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1682
!
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1683
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1684
nameForChanges
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1685
    "return a reasonable filename to store the changes into.
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1686
     This is the basename of the current image with '.img' replaced
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1687
     by '.chg', or, if not running from an image, the default name 'st.chg'"
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1688
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1689
    ^ 'changes'.
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1690
    ^ self imageBaseName , '.chg'
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1691
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1692
    "
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1693
     ObjectMemory nameForChanges    
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1694
    "
22
847106305963 *** empty log message ***
claus
parents: 13
diff changeset
  1695
!
847106305963 *** empty log message ***
claus
parents: 13
diff changeset
  1696
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1697
snapShot
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1698
    "create a snapshot file containing all of the current state."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1699
22
847106305963 *** empty log message ***
claus
parents: 13
diff changeset
  1700
    self snapShotOn:(self nameForSnapshot)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1701
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1702
    "
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1703
     ObjectMemory snapShot
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1704
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1705
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1706
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1707
snapShotOn:aFileName
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1708
    "create a snapshot in the given file"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1709
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1710
    |ok oldImageName|
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1711
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1712
    "
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1713
     keep a save version - just in case something
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1714
     bad happens while writing the image.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1715
     (could be st/x internal error or file-system errors etc)
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1716
    "
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1717
    (OperatingSystem isValidPath:aFileName) ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1718
	OperatingSystem renameFile:aFileName to:(aFileName , '.sav').
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1719
    ].
22
847106305963 *** empty log message ***
claus
parents: 13
diff changeset
  1720
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1721
    "
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1722
     give others a chance to fix things
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1723
    "
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1724
    self changed:#save.
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1725
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1726
    "
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1727
     ST-80 compatibility; send #preSnapshot to all classes
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1728
    "
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1729
    Smalltalk allBehaviorsDo:[:aClass |
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1730
	aClass preSnapshot
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1731
    ].
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1732
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1733
    "
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1734
     save the name with it ...
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1735
    "
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1736
    oldImageName := ImageName.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1737
    ImageName := aFileName.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1738
    ok := self primSnapShotOn:aFileName.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1739
    ImageName := oldImageName.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1740
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1741
    ok ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1742
	Class addChangeRecordForSnapshot:aFileName.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1743
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1744
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1745
	"
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1746
	 ST-80 compatibility; send #postSnapshot to all classes
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1747
	"
202
40ca7cc6fb9c *** empty log message ***
claus
parents: 194
diff changeset
  1748
	Smalltalk allBehaviorsDo:[:aClass |
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1749
	    aClass postSnapshot
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1750
	].
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1751
    ].
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1752
    ^ ok
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1753
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1754
    "
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1755
     ObjectMemory snapShotOn:'myimage.img'
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1756
    "
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1757
!
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1758
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1759
primSnapShotOn:aFileName
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1760
    "create a snapshot in the given file.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1761
     Low level entry. Does not notify classes or write an entry to
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1762
     the changes file. Also, no image backup is created. Returns true if
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1763
     the snapshot worked, false if it failed for some reason.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1764
     This method should not be used in normal cases."
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1765
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1766
    |ok|
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1767
13
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1768
%{  /* STACK:32000 */
62303f84ff5f *** empty log message ***
claus
parents: 10
diff changeset
  1769
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1770
    OBJ __snapShotOn();
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1771
    OBJ funny = @symbol(funnySnapshotSymbol);
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1772
56
be0ed17e6f85 *** empty log message ***
claus
parents: 22
diff changeset
  1773
    if (__isString(aFileName)) {
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1774
	BLOCKINTERRUPTS();
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1775
	ok = __snapShotOn(__context, _stringVal(aFileName), funny);
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1776
	UNBLOCKINTERRUPTS();
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1777
    }
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1778
%}.
22
847106305963 *** empty log message ***
claus
parents: 13
diff changeset
  1779
    ^ ok
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1780
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1781
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1782
applicationImageOn:aFileName for:startupClass selector:startupSelector
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1783
    "create a snapshot which will come up without any views 
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1784
     but starts up an application by sending startupClass the startupSelector.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1785
     EXPERIMENTAL and unfinished. Dont use this method."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1786
2
claus
parents: 1
diff changeset
  1787
    |viewsKnown savedIdleBlocks savedTimeoutBlocks savedTranscript
claus
parents: 1
diff changeset
  1788
     savedRoot|
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1789
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1790
    viewsKnown := Display knownViews.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1791
    savedIdleBlocks := Display idleBlocks.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1792
    savedTimeoutBlocks := Display timeOutBlocks.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1793
    savedTranscript := Transcript.
2
claus
parents: 1
diff changeset
  1794
    savedRoot := RootView.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1795
10
claus
parents: 5
diff changeset
  1796
    "a kludge: save image with modified knownViews, no idle- and timeoutblocks
claus
parents: 5
diff changeset
  1797
     and also Transcript set to StdErr ..."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1798
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1799
    Display knownViews:nil.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1800
    Display idleBlocks:nil.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1801
    Display timeOutBlocks:nil.
2
claus
parents: 1
diff changeset
  1802
    RootView := nil.
claus
parents: 1
diff changeset
  1803
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1804
    Transcript := Stderr.
10
claus
parents: 5
diff changeset
  1805
    Smalltalk startupClass:startupClass selector:startupSelector arguments:nil.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1806
    self snapShotOn:aFileName.
10
claus
parents: 5
diff changeset
  1807
    Smalltalk startupClass:nil selector:nil arguments:nil.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1808
2
claus
parents: 1
diff changeset
  1809
    RootView := savedRoot.
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1810
    Transcript := savedTranscript.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1811
    Display knownViews:viewsKnown.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1812
    Display idleBlocks:savedIdleBlocks.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1813
    Display timeOutBlocks:savedTimeoutBlocks
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1814
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1815
    "ObjectMemory applicationImageOn:'draw.img' for:DrawTool selector:#start"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1816
    "ObjectMemory applicationImageOn:'pm.img' for:PMSimulator selector:#start"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1817
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1818
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1819
minimumApplicationImageOn:aFileName for:startupClass selector:startupSelector
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1820
    "create a snapshot which will come up without any views 
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1821
     but starts up an application by sending startupClass the startupSelector.
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1822
     All unneeded info is stripped from the saved image.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1823
     EXPERIMENTAL and unfinished. Dont use this method."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1824
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1825
    "create a temporary image, for continuation"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1826
    self snapShotOn:'temp.img'.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1827
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1828
    Display knownViews do:[:aView |
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1829
	aView notNil ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1830
	    aView superView isNil ifTrue:[
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1831
		aView destroy
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1832
	    ]
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1833
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1834
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1835
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1836
    self stripImage.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1837
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1838
    self applicationImageOn:aFileName for:startupClass selector:startupSelector.
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1839
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1840
    "continue in old image"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1841
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1842
    OperatingSystem exec:(Arguments at:1)
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1843
	   withArguments:#('smalltalk' '-i' 'temp.img') , (Arguments copyFrom:2)
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1844
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1845
    "ObjectMemory minimumApplicationImageOn:'clock1.img' for:Clock selector:#start"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1846
    "ObjectMemory applicationImageOn:'clock2.img' for:Clock selector:#start"
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1847
!
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1848
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1849
stripImage
93
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1850
    "remove all unneeded stuff from the image - much more is possible here.
e31220cb391f *** empty log message ***
claus
parents: 88
diff changeset
  1851
     EXPERIMENTAL and unfinished. Dont use this method."
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1852
2
claus
parents: 1
diff changeset
  1853
    "remove all class comments & source"
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1854
2
claus
parents: 1
diff changeset
  1855
    Smalltalk allBehaviorsDo:[:aClass |
159
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1856
	aClass setComment:nil.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1857
	aClass methodArray do:[:aMethod |
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1858
	    aMethod source:''.
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1859
	    aMethod category:#none 
514c749165c3 *** empty log message ***
claus
parents: 133
diff changeset
  1860
	]
1
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1861
    ].
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1862
    self garbageCollect
a27a279701f8 Initial revision
claus
parents:
diff changeset
  1863
! !