/[eiffelstudio]/FreeELKS/trunk/library/kernel/memory.e
ViewVC logotype

Contents of /FreeELKS/trunk/library/kernel/memory.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 91424 - (show annotations)
Tue Oct 26 18:39:32 2004 UTC (15 years, 3 months ago) by manus_eiffel
File size: 11284 byte(s)
Initial revision

1 indexing
2
3 description: "[
4 Facilities for tuning up the garbage collection mechanism.
5 This class may be used as ancestor by classes needing its facilities.
6 ]"
7
8 status: "See notice at end of class"
9 date: "$Date$"
10 revision: "$Revision$"
11
12 class
13 MEMORY
14
15 inherit
16 DISPOSABLE
17
18 MEM_CONST
19
20 feature -- Measurement
21
22 memory_statistics (memory_type: INTEGER): MEM_INFO is
23 -- Memory usage information for `memory_type'
24 require
25 type_ok:
26 memory_type = Total_memory or
27 memory_type = Eiffel_memory or
28 memory_type = C_memory
29 do
30 create Result.make (memory_type)
31 end
32
33 gc_statistics (collector_type: INTEGER): GC_INFO is
34 -- Garbage collection information for `collector_type'.
35 require
36 type_ok:
37 collector_type = Full_collector or
38 collector_type = Incremental_collector
39 do
40 create Result.make (collector_type)
41 end
42
43 feature -- Status report
44
45 memory_threshold: INTEGER is
46 -- Minimum amount of bytes to be allocated before
47 -- starting an automatic garbage collection.
48 external
49 "C | %"eif_memory.h%""
50 alias
51 "mem_tget"
52 end
53
54 collection_period: INTEGER is
55 -- Period of full collection.
56 -- If the environment variable EIF_FULL_COLLECTION_PERIOD
57 -- is defined, it is set to the closest reasonable
58 -- value from it.
59 -- If null, no full collection is launched.
60 external
61 "C | %"eif_memory.h%""
62 alias
63 "mem_pget"
64 end
65
66 coalesce_period: INTEGER is
67 -- Period of full coalesce (in number of collections)
68 -- If the environment variable EIF_FULL_COALESCE_PERIOD
69 -- is defined, it is set to the closest reasonable
70 -- value from it.
71 -- If null, no full coalescing is launched.
72 external
73 "C | %"eif_memory.h%""
74 alias
75 "eif_coalesce_period"
76 end
77
78 collecting: BOOLEAN is
79 -- Is garbage collection enabled?
80 external
81 "C | %"eif_memory.h%""
82 alias
83 "gc_ison"
84 end
85
86 largest_coalesced_block: INTEGER is
87 -- Size of largest coalesced block since last call to
88 -- `largest_coalesced'; 0 if none.
89 external
90 "C use %"eif_memory.h%""
91 alias
92 "mem_largest"
93 end
94
95 max_mem: INTEGER is
96 -- Maximum amount of bytes the run-time can allocate.
97 external
98 "C | %"eif_memory.h%""
99 alias
100 "eif_get_max_mem"
101 end
102
103 chunk_size: INTEGER is
104 -- Minimal size of a memory chunk. The run-time always
105 -- allocates a multiple of this size.
106 -- If the environment variable EIF_MEMORY_CHUNK
107 -- is defined, it is set to the closest reasonable
108 -- value from it.
109 external
110 "C | %"eif_memory.h%""
111 alias
112 "eif_get_chunk_size"
113 end
114
115 tenure: INTEGER is
116 -- Maximum age of object before being considered
117 -- as old (old objects are not scanned during
118 -- partial collection).
119 -- If the environment variable EIF_TENURE_MAX
120 -- is defined, it is set to the closest reasonable
121 -- value from it.
122 external
123 "C | %"eif_memory.h%""
124 alias
125 "eif_tenure"
126 end
127
128 generation_object_limit: INTEGER is
129 -- Maximum size of object in generational scavenge zone.
130 -- If the environment variable EIF_GS_LIMIT
131 -- is defined, it is set to the closest reasonable
132 -- value from it.
133 external
134 "C | %"eif_memory.h%""
135 alias
136 "eif_generation_object_limit"
137 end
138
139 scavenge_zone_size: INTEGER is
140 -- Size of generational scavenge zone.
141 -- If the environment variable EIF_MEMORY_SCAVENGE
142 -- is defined, it is set to the closest reasonable
143 -- value from it.
144
145 external
146 "C | %"eif_memory.h%""
147 alias
148 "eif_scavenge_zone_size"
149 end
150
151 feature -- Status report
152
153 referers (an_object: ANY): SPECIAL [ANY] is
154 -- Objects that refer to `an_object'.
155 do
156 Result := find_referers ($an_object, special_any_dynamic_type)
157 end
158
159 objects_instance_of (an_object: ANY): SPECIAL [ANY] is
160 -- Objects that have same dynamic type as `an_object'.
161 do
162 Result := find_instance_of (feature {ISE_RUNTIME}.dynamic_type ($an_object),
163 special_any_dynamic_type)
164 end
165
166 memory_map: HASH_TABLE [ARRAYED_LIST [ANY], INTEGER] is
167 -- Retrieves all object in system as a table indexed by dynamic type
168 -- where elements are all instances of a given data type.
169 local
170 i, nb, dtype: INTEGER
171 l_spec: SPECIAL [ANY]
172 l_item: ANY
173 l_list: ARRAYED_LIST [ANY]
174 do
175 -- First get all object instances in runtime.
176 l_spec := find_all_instances (special_any_dynamic_type)
177
178 -- Now create table indexed by dynamic type. For a given
179 -- dynamic type, we will have a list of all objects of
180 -- this type.
181 create Result.make (100)
182 from
183 i := 0
184 nb := l_spec.count
185 until
186 i >= nb
187 loop
188 l_item := l_spec.item (i)
189 if l_item /= Void then
190 dtype := feature {ISE_RUNTIME}.dynamic_type ($l_item)
191 Result.search (dtype)
192 if Result.found then
193 l_list := Result.found_item
194 else
195 create l_list.make (5)
196 Result.put (l_list, dtype)
197 end
198 l_list.extend (l_item)
199 end
200 i := i + 1
201 end
202 end
203
204 memory_count_map: HASH_TABLE [INTEGER, INTEGER] is
205 -- Number of instances per dynamic type present in system.
206 -- Same as `memory_map' except that no references on the objects themselves
207 -- is kept.
208 local
209 i, nb, dtype: INTEGER
210 l_spec: SPECIAL [ANY]
211 l_item: ANY
212 do
213 -- First get all object instances in runtime.
214 l_spec := find_all_instances (special_any_dynamic_type)
215
216 -- Now create table indexed by dynamic type. For a given
217 -- dynamic type, we will count all objects of this type.
218 create Result.make (100)
219 from
220 i := 0
221 nb := l_spec.count
222 until
223 i >= nb
224 loop
225 l_item := l_spec.item (i)
226 if l_item /= Void then
227 dtype := feature {ISE_RUNTIME}.dynamic_type ($l_item)
228 Result.search (dtype)
229 if Result.found then
230 Result.force (Result.found_item + 1, dtype)
231 else
232 Result.put (1, dtype)
233 end
234 end
235 i := i + 1
236 end
237 end
238
239 feature -- Status setting
240
241 collection_off is
242 -- Disable garbage collection.
243 external
244 "C | %"eif_garcol.h%""
245 alias
246 "gc_stop"
247 end
248
249 collection_on is
250 -- Enable garbage collection.
251 external
252 "C | %"eif_garcol.h%""
253 alias
254 "gc_run"
255 end
256
257 allocate_fast is
258 -- Enter ``speed'' mode: will optimize speed of memory
259 -- allocation rather than memory usage.
260 external
261 "C | %"eif_memory.h%""
262 alias
263 "mem_speed"
264 end
265
266 allocate_compact is
267 -- Enter ``memory'' mode: will try to compact memory
268 -- before requesting more from the operating system.
269 external
270 "C | %"eif_memory.h%""
271 alias
272 "mem_slow"
273 end
274
275 allocate_tiny is
276 -- Enter ``tiny'' mode: will enter ``memory'' mode
277 -- after having freed as much memory as possible.
278 external
279 "C | %"eif_memory.h%""
280 alias
281 "mem_tiny"
282 end
283
284 enable_time_accounting is
285 -- Enable GC time accouting, accessible in `gc_statistics'.
286 do
287 gc_monitoring (True)
288 end
289
290 disable_time_accounting is
291 -- Disable GC time accounting (default).
292 do
293 gc_monitoring (False)
294 end
295
296 set_memory_threshold (value: INTEGER) is
297 -- Set a new `memory_threshold' in bytes. Whenever the memory
298 -- allocated for Eiffel reaches this value, an automatic
299 -- collection is performed.
300 require
301 positive_value: value > 0
302 external
303 "C | %"eif_memory.h%""
304 alias
305 "mem_tset"
306 end
307
308 set_collection_period (value: INTEGER) is
309 -- Set `collection_period'. Every `value' collection,
310 -- the Garbage collector will perform a collection
311 -- on the whole memory (full collection), otherwise
312 -- a simple partial collection is done.
313 require
314 positive_value: value >= 0
315 external
316 "C | %"eif_memory.h%""
317 alias
318 "mem_pset"
319 end
320
321 set_coalesce_period (value: INTEGER) is
322 -- Set `coalesce_period'. Every `value' collection,
323 -- the Garbage Collector will coalesce
324 -- the whole memory.
325 require
326 positive_value: value >= 0
327 external
328 "C | %"eif_memory.h%""
329 alias
330 "eif_set_coalesce_period"
331 end
332
333 set_max_mem (value: INTEGER) is
334 -- Set the maximum amount of memory the run-time can allocate.
335 require
336 positive_value: value > 0
337 external
338 "C | %"eif_memory.h%""
339 alias
340 "eif_set_max_mem"
341 end
342
343 feature -- Removal
344
345 dispose is
346 -- Action to be executed just before garbage collection
347 -- reclaims an object.
348 -- Default version does nothing; redefine in descendants
349 -- to perform specific dispose actions. Those actions
350 -- should only take care of freeing external resources;
351 -- they should not perform remote calls on other objects
352 -- since these may also be dead and reclaimed.
353 do
354 end
355
356 free (object: ANY) is
357 -- Free `object', by-passing garbage collection.
358 -- Erratic behavior will result if the object is still
359 -- referenced.
360 do
361 mem_free ($object)
362 end
363
364 mem_free (addr: POINTER) is
365 -- Free memory of object at `addr'.
366 -- (Preferred interface is `free'.)
367 external
368 "C signature (EIF_REFERENCE) use %"eif_memory.h%""
369 end
370
371 full_coalesce is
372 -- Coalesce the whole memory: merge adjacent free
373 -- blocks to reduce fragmentation. Useful, when
374 -- a lot of memory is allocated with garbage collector off.
375 external
376 "C use %"eif_memory.h%""
377 alias
378 "mem_coalesc"
379 end
380
381 collect is
382 -- Force a partial collection cycle if garbage
383 -- collection is enabled; do nothing otherwise.
384 external
385 "C | %"eif_eiffel.h%""
386 end
387
388 full_collect is
389 -- Force a full collection cycle if garbage
390 -- collection is enabled; do nothing otherwise.
391 external
392 "C | %"eif_garcol.h%""
393 alias
394 "plsc"
395 end
396
397 feature {NONE} -- Implementation
398
399 gc_monitoring (flag: BOOLEAN) is
400 -- Set up GC monitoring according to `flag'
401 external
402 "C | %"eif_memory.h%""
403 alias
404 "gc_mon"
405 end
406
407 find_referers (target: POINTER; result_type: INTEGER): SPECIAL [ANY] is
408 external
409 "C signature (EIF_REFERENCE, EIF_INTEGER): EIF_REFERENCE use %"eif_traverse.h%""
410 end
411
412 find_instance_of (dtype, result_type: INTEGER): SPECIAL [ANY] is
413 external
414 "C signature (EIF_INTEGER, EIF_INTEGER): EIF_REFERENCE use %"eif_traverse.h%""
415 end
416
417 find_all_instances (result_type: INTEGER): SPECIAL [ANY] is
418 external
419 "C signature (EIF_INTEGER): EIF_REFERENCE use %"eif_traverse.h%""
420 end
421
422 special_any_dynamic_type: INTEGER is
423 -- Dynamic type ID of an instance of `SPECIAL [ANY]'
424 local
425 a: ARRAY [ANY]
426 spec: SPECIAL [ANY]
427 once
428 create a.make (0, 0)
429 spec := a.area
430 Result := feature {ISE_RUNTIME}.dynamic_type ($spec)
431 end
432
433 indexing
434
435 library: "[
436 EiffelBase: Library of reusable components for Eiffel.
437 ]"
438
439 status: "[
440 Copyright 1986-2001 Interactive Software Engineering (ISE).
441 For ISE customers the original versions are an ISE product
442 covered by the ISE Eiffel license and support agreements.
443 ]"
444
445 license: "[
446 EiffelBase may now be used by anyone as FREE SOFTWARE to
447 develop any product, public-domain or commercial, without
448 payment to ISE, under the terms of the ISE Free Eiffel Library
449 License (IFELL) at http://eiffel.com/products/base/license.html.
450 ]"
451
452 source: "[
453 Interactive Software Engineering Inc.
454 ISE Building
455 360 Storke Road, Goleta, CA 93117 USA
456 Telephone 805-685-1006, Fax 805-685-6869
457 Electronic mail <info@eiffel.com>
458 Customer support http://support.eiffel.com
459 ]"
460
461 info: "[
462 For latest info see award-winning pages: http://eiffel.com
463 ]"
464
465 end -- class MEMORY
466
467
468

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23