factor/core/tools/memory.facts

64 lines
4.3 KiB
Plaintext
Raw Permalink Normal View History

2006-03-25 01:06:52 -05:00
IN: memory
2006-08-01 17:41:10 -04:00
USING: errors help test ;
2006-06-04 16:20:40 -04:00
2006-09-26 19:00:41 -04:00
HELP: data-gc ( n -- )
2006-06-04 16:20:40 -04:00
{ $values { "n" "a positive integer" } }
{ $description "Collects all generations up to and including the " { $snippet "n" } "th generation. The nursery where new objects are allocated is generation 0, and tenured space is generation " { $snippet "g-1" } " where " { $snippet "g" } " is the value output by " { $link generations } "." } ;
2006-08-16 21:55:53 -04:00
HELP: gc-time ( -- n )
2006-06-04 16:20:40 -04:00
{ $values { "n" "a timestamp in milliseconds" } }
{ $description "Outputs the total time spent in garbage collection during this Factor session." }
{ $examples "This word is used by " { $link time } " to measure the time spent in garbage collection during the execution of a quotation." } ;
2006-09-26 01:08:05 -04:00
HELP: data-room ( -- cards semi generations )
{ $values { "cards" "number of bytes reserved for card marking" } { "semi" "number of bytes reserved for tenured semi-space" } { "generations" "array of free/total bytes pairs" } }
{ $description "Queries the runtime for memory usage information. Use " { $link room. } " for a pretty memory usage display." }
{ $see-also code-room } ;
HELP: code-room ( -- code-free code-total )
{ $values { "code-free" "bytes free in the code heap" } { "code-total" "total bytes in the code heap" } }
{ $description "Queries the runtime for memory usage information. Use " { $link room. } " for a pretty memory usage display." }
{ $see-also data-room } ;
2006-06-04 16:20:40 -04:00
2006-08-16 21:55:53 -04:00
HELP: size ( obj -- n )
2006-06-04 16:20:40 -04:00
{ $values { "obj" "an object" } { "n" "a size in bytes" } }
{ $description "Outputs the size of the object in memory, in bytes. Tagged immediate objects such as fixnums and " { $link f } " will yield a size of 0." } ;
2006-03-25 01:06:52 -05:00
2006-08-16 21:55:53 -04:00
HELP: full-gc
2006-03-25 01:06:52 -05:00
{ $description "Performs a full garbage collection." } ;
2006-08-16 21:55:53 -04:00
HELP: room.
2006-03-25 01:06:52 -05:00
{ $description "Prints an overview of memory usage broken down by generation and zone." } ;
2006-08-16 21:55:53 -04:00
HELP: begin-scan ( -- )
2006-06-04 16:20:40 -04:00
{ $description "Moves all objects to tenured space, disables the garbage collector, and resets the heap scan pointer to point at the first object in the heap. The " { $link next-object } " word can then be called to advance the heap scan pointer and return successive objects."
$terpri
"This word must always be paired with a call to " { $link end-scan } "." }
{ $notes "This is a low-level facility and can be dangerous. Use the " { $link each-object } " combinator instead." } ;
2006-08-16 21:55:53 -04:00
HELP: next-object ( -- obj )
2006-06-04 16:20:40 -04:00
{ $description "Outputs the object at the heap scan pointer, and then advances the heap scan pointer. If the end of the heap has been reached, outputs " { $link f } ". This is unambiguous since the " { $link f } " object is tagged immediate and not actually stored in the heap." }
2006-08-01 17:35:00 -04:00
{ $errors "Throws a " { $link heap-scan-error. } " if called outside a " { $link begin-scan } "/" { $link end-scan } " pair." }
2006-06-04 16:20:40 -04:00
{ $notes "This is a low-level facility and can be dangerous. Use the " { $link each-object } " combinator instead." } ;
2006-08-16 21:55:53 -04:00
HELP: end-scan ( -- )
2006-06-04 16:20:40 -04:00
{ $description "Finishes a heap iteration by re-enabling the garbage collector. This word must always be paired with a call to " { $link begin-scan } "." }
{ $notes "This is a low-level facility and can be dangerous. Use the " { $link each-object } " combinator instead." } ;
2006-08-16 21:55:53 -04:00
HELP: each-object
2006-03-25 01:06:52 -05:00
{ $values { "quot" "a quotation with stack effect " { $snippet "( obj -- )" } } }
{ $description "Applies a quotation to each object in the heap. The garbage collector is switched off while this combinator runs, so the given quotation must not allocate too much memory." }
2006-06-10 01:40:11 -04:00
{ $notes "This word is the low-level facility used to implement the " { $link instances } " and " { $link heap-stats. } " words." } ;
2006-03-25 01:06:52 -05:00
2006-08-16 21:55:53 -04:00
HELP: instances
2006-03-25 01:06:52 -05:00
{ $values { "quot" "a quotation with stack effect " { $snippet "( obj -- ? )" } } { "seq" "a fresh sequence" } }
{ $description "Outputs a sequence of all objects in the heap which satisfy the quotation." }
{ $notes "This word relies on " { $link each-object } ", so in particular the garbage collector is switched off while it runs and the given quotation must not allocate too much memory." } ;
2006-08-16 21:55:53 -04:00
HELP: heap-stats
2006-03-25 01:06:52 -05:00
{ $values { "counts" "a hashtable mapping class words to integers" } { "sizes" "a hashtable mapping class words to integers" } }
{ $description "Outputs a pair of hashtables, holding class instance counts and instance memory usage, respectively." } ;
2006-08-16 21:55:53 -04:00
HELP: heap-stats.
2006-03-25 01:06:52 -05:00
{ $description "For each class, prints the number of instances and total memory consumed by those instances." } ;