memory management More...
Go to the source code of this file.
Macros | |
#define | LONELY 1 |
#define | assert(N) |
#define | UNCHECKED(P) (! *((GENERIC)(P)+delta)) |
Functions | |
char * | GetStrOption (char *name, char *def) |
GetStrOption. More... | |
int | GetBoolOption (char *name) |
GetBoolOption. More... | |
int | GetIntOption (char *name, int def) |
GetIntOption. More... | |
void | pchoices () |
pchoices More... | |
void | print_undo_stack () |
print_undo_stack More... | |
long | bounds_undo_stack () |
bounds_undo_stack More... | |
static void | check_psi_list () |
static void | check_resid_list () |
static void | check_choice () |
static void | check_undo_stack () |
void | fail_all () |
fail_all More... | |
static void | compress () |
compress More... | |
static long | unchecked (GENERIC *p, long len) |
unchecked More... | |
static void | check_string (GENERIC *s) |
check_string More... | |
static void | check_bytedata (GENERIC *s) |
check_bytedata More... | |
static void | check_code (ptr_int_list *c) |
check_code More... | |
static void | check_pair_list (ptr_pair_list *p) |
check_pair_list More... | |
static void | check_triple_list (ptr_triple_list *p) |
check_triple_list More... | |
static void | check_kids (ptr_int_list *c) |
check_kids More... | |
static void | check_operator_data (ptr_operator_data *op) |
check_operator_data More... | |
static void | check_module () |
static void | check_keyword () |
static void | check_module_list (ptr_int_list *c) |
check_module_list More... | |
static void | check_module_tree (ptr_node *n) |
check_module_tree More... | |
static void | check_module (ptr_module *m) |
check_module More... | |
void | check_hash_table (ptr_hash_table table) |
check_hash_table More... | |
static void | check_keyword (ptr_keyword *k) |
check_keyword More... | |
void | check_definition (ptr_definition *d) |
check_definition More... | |
void | check_definition_list () |
check_definition_list More... | |
static void | check_def_code (ptr_definition *d) |
check_def_code More... | |
static void | check_def_rest (ptr_definition *d) |
check_def_rest More... | |
static void | check_symbol (ptr_node *n) |
check_symbol More... | |
static void | check_type_disj (ptr_int_list *p) |
check_type_disj More... | |
static void | check_goal_stack (ptr_goal *g) |
check_goal_stack More... | |
static void | check_resid (ptr_residuation *r) |
check_resid More... | |
void | check_resid_block (ptr_resid_block *rb) |
check_resid_block More... | |
void | check_psi_term (ptr_psi_term *t) |
check_psi_term More... | |
void | check_attr (ptr_node *n) |
check_attr More... | |
void | check_gamma_code () |
check_gamma_code More... | |
static void | check_gamma_rest () |
check_gamma_rest More... | |
static void | check_undo_stack (ptr_stack *s) |
check_undo_stack More... | |
static void | check_choice_structs (ptr_choice_point *c) |
check_choice_structs More... | |
static void | check_choice (ptr_choice_point *c) |
check_choice More... | |
static void | check_special_addresses () |
check_special_addresses More... | |
static void | check_psi_list (ptr_int_list *l) |
check_psi_list More... | |
static void | check_resid_list (ptr_resid_list *l) |
check_resid_list More... | |
static void | check_var (ptr_node *n) |
static void | check () |
check More... | |
void | print_gc_info (long timeflag) |
print_gc_info More... | |
void | garbage () |
garbage More... | |
GENERIC | heap_alloc (long s) |
heap_alloc More... | |
GENERIC | stack_alloc (long s) |
stack_alloc More... | |
void | init_memory () |
init_memory () More... | |
long | memory_check () |
memory_check More... | |
Variables | |
static long | delta |
static long | pass |
static struct tms | last_garbage_time |
static float | gc_time |
static float | life_time |
memory management
Definition in file memory.c.
long bounds_undo_stack | ( | ) |
bounds_undo_stack
Address field in undo_stack is within range The only valid address outside this range is that of xevent_state
Definition at line 142 of file memory.c.
References wl_stack::aaaa_3, FALSE, mem_base, mem_limit, wl_stack::next, TRUE, wl_stack::type, undo_action, undo_stack, and VALID_ADDRESS.
|
static |
check
CHECK This routine checks all pointers and psi_terms to find out which memory cells must be preserved and which can be discarded.
This routine explores all known structures. It is vital that it should visit them all exactly once. It thus creates a map of what is used in memory, which COMPRESS uses to compact the memory and recalculate the addresses. Exploration of these structures should be done in exactly the same order in both passes. If it is the second pass, pointers are assigned their new values.
A crucial property of this routine: In pass 2, a global variable (i.e. a root for GC) must be updated before it is accessed. E.g. don't use the variable goal_stack before updating it.
Definition at line 1299 of file memory.c.
References aborthooksym, abortsym, add_module1, add_module2, add_module3, aim, alist, and, apply, assert, bi_module, boolpredsym, bounds_undo_stack(), built_in, call_handlersym, check_choice(), check_choice_structs(), check_definition(), check_definition_list(), check_gamma_code(), check_gamma_rest(), check_goal_stack(), check_module(), check_module_tree(), check_psi_term(), check_resid_list(), check_special_addresses(), check_string(), check_sys_definitions(), check_undo_stack(), check_var(), choice_stack, colonsym, commasym, comment, constant, current_module, cut, day_attr, delay_checksym, disj_nil, disjunction, dynamicsym, encodesym, eof, eqsym, error_psi_term, eval_argsym, final_dot, final_question, funcsym, functor, fx_sym, fy_sym, goal_stack, hour_attr, iff, input_state, inputfilesym, integer, lf_false, lf_true, life_or, listingsym, loadsym, minus_symbol, minute_attr, module_table, month_attr, nil, no_module, nothing, null_psi_term, nullsym, old_saved_psi_term, old_state, one, opsym, pass, predsym, quote, quoted_string, real, resid_aim, resid_vars, saved_psi_term, second_attr, staticsym, stdin_state, stream, succeed, such_that, syntax_module, sys_module, three, timesym, top, tracesym, TRUE, two, typesym, undo_stack, user_module, var_tree, variable, weekday_attr, x_module, xbutton_event, xconfigure_event, xdestroy_event, xdisplay, xdisplaylist, xdrawable, xenter_event, xevent, xevent_existing, xevent_list, xexpose_event, xf_sym, xfx_sym, xfy_sym, xgc, xkeyboard_event, xleave_event, xmisc_event, xmotion_event, xpixmap, xwindow, year_attr, yf_sym, and yfx_sym.
void check_attr | ( | ptr_node * | n | ) |
check_attr
ptr_node | *n |
CHECK_ATTR(attribute-tree) Check an attribute tree. (Could improve this by randomly picking left or right subtree for last call optimization. This would never overflow, even on very skewed attribute trees.)
Definition at line 1054 of file memory.c.
References check_psi_term(), check_string(), and unchecked().
|
static |
check_bytedata
GENERIC | *s |
CHECK_BYTEDATA(s) Claim the memory used by a block of bytes
Definition at line 450 of file memory.c.
References delta, MAX_BUILT_INS, pass, and unchecked().
|
static |
|
static |
check_choice
ptr_choice_point | *c |
CHECK_CHOICE(c) This routine checks all choice points.
Definition at line 1184 of file memory.c.
References check_goal_stack(), and check_undo_stack().
|
static |
check_choice_structs
ptr_choice_point | *c |
Definition at line 1169 of file memory.c.
References unchecked().
|
static |
check_code
ptr_int_list | *c |
CHECK_CODE(c) Claim the memory used by a type code (=list of integers).
Definition at line 486 of file memory.c.
References unchecked().
|
static |
check_def_code
ptr_definition | *d |
CHECK_DEF_CODE(d) This routine checks the CODE field in a definition. It may only be invoked by CHECK_GAMMA.
Definition at line 720 of file memory.c.
References check_code(), and unchecked().
|
static |
check_def_rest
ptr_definition | *d |
CHECK_DEF_REST(d) This routine checks the other fields in a definition. It may only be invoked by CHECK_GAMMA_REST.
Definition at line 737 of file memory.c.
References check_keyword(), check_kids(), check_operator_data(), check_pair_list(), check_triple_list(), and type_it.
void check_definition | ( | ptr_definition * | d | ) |
check_definition
ptr_definition | *d |
CHECK_DEFINITION This goes through the type tree which contains the parents and children lists for all types, and the attributed code. The code field is not checked as this has been done separately by CHECK_GAMMA.
Definition at line 662 of file memory.c.
References check_code(), check_keyword(), check_kids(), check_operator_data(), check_pair_list(), check_psi_term(), check_triple_list(), wl_definition::keyword, wl_keyword::symbol, type_it, and unchecked().
void check_definition_list | ( | ) |
check_definition_list
CHECK_DEFINITION_LIST This checks the entire list of definitions.
Definition at line 699 of file memory.c.
References check_definition(), and first_definition.
void check_gamma_code | ( | ) |
check_gamma_code
CHECK_GAMMA_CODE() Check and update the code reversing table. In this part, only the codes are checked in the definitions, this is vital because these codes are used later to distinguish between the various data types and to determine the type of the VALUE field in psi_terms. Misunderstanding this caused a lot of bugs in the GC.
Definition at line 1078 of file memory.c.
References check_def_code(), gamma_table, type_count, and unchecked().
|
static |
check_gamma_rest
CHECK_GAMMA_REST() Check and update the code reversing table.
Definition at line 1095 of file memory.c.
References check_def_rest(), gamma_table, and type_count.
|
static |
check_goal_stack
ptr_goal | *g |
CHECK_GOAL_STACK Check the goal_stack. This is quite complicated as each type of goal (prove, unify, eval, eval_cut etc...) gives its own meanings to the three other fields (A,B and C) present in each goal.
Definition at line 800 of file memory.c.
References check_pair_list(), check_psi_term(), check_resid_block(), check_string(), check_type_disj(), choice_stack, clause, DEFRULES, del_clause, disj, Errorline(), eval, eval_cut, fail, freeze_cut, general_cut, implies_cut, load, LONELY, match, pass, prove, retract, type_disj, unchecked(), unify, unify_noeval, and what_next.
void check_hash_table | ( | ptr_hash_table | table | ) |
check_hash_table
ptr_hash_table | table |
CHECK_HASH_TABLE(table) Check a hash table of keywords. The actual table is not stored within LIFE memory.
Definition at line 625 of file memory.c.
References check_keyword(), wl_hash_table::data, and wl_hash_table::size.
|
static |
|
static |
check_keyword
ptr_keyword | *k |
CHECK_KEYWORD(k) Checks a keyword.
Definition at line 642 of file memory.c.
References check_definition(), check_module(), check_string(), and unchecked().
|
static |
check_kids
ptr_int_list | *c |
CHECK_KIDS(c) Check a list of parents or children of a given type.
Definition at line 535 of file memory.c.
References check_definition(), and unchecked().
|
static |
|
static |
check_module
ptr_module | *m |
CHECK_MODULE(m) Checks a module.
Definition at line 605 of file memory.c.
References check_hash_table(), check_module_list(), check_string(), and unchecked().
|
static |
check_module_list
ptr_int_list | *c |
CHECK_MODULE_LIST(c) Check a list of modules.
Definition at line 570 of file memory.c.
References check_module(), and unchecked().
|
static |
check_module_tree
ptr_node | *n |
CHECK_MODULE_TREE This goes through the module table, checking all nodes.
Definition at line 587 of file memory.c.
References check_module(), check_string(), and unchecked().
|
static |
check_operator_data
ptr_operator_data | *op |
CHECK_OPERATOR_DATA(op) Explore a list of operator declarations.
Definition at line 551 of file memory.c.
References unchecked().
|
static |
check_pair_list
ptr_pair_list *p
CHECK_PAIR_LIST Checks a list of <GOAL,BODY> pairs.
Definition at line 500 of file memory.c.
References check_psi_term(), and unchecked().
|
static |
|
static |
check_psi_list
ptr_int_list | *l |
CHECK_PSI_LIST Update all the values in the list of residuation variables, which is a list of psi_terms.
Definition at line 1235 of file memory.c.
References check_psi_term(), and unchecked().
void check_psi_term | ( | ptr_psi_term * | t | ) |
check_psi_term
ptr_psi_term | *t |
CHECK_PSI_TERM(t) Explore a psi_term.
Definition at line 987 of file memory.c.
References alist, assert, check_attr(), check_bytedata(), check_definition(), check_resid(), check_string(), choice_stack, cut, Errorline(), heap_pointer, LONELY, mem_limit, NULL, pass, quoted_string, REAL, real, stream, sub_type(), sys_bytedata, unchecked(), and variable.
|
static |
check_resid
ptr_residuation | *r |
CHECK_RESID(r) Explore a list of residuations.
Definition at line 914 of file memory.c.
References alist, check_bytedata(), check_code(), check_definition(), check_goal_stack(), check_string(), choice_stack, wl_definition::code, cut, LONELY, pass, quoted_string, REAL, real, sub_CodeType(), sys_bytedata, unchecked(), and variable.
void check_resid_block | ( | ptr_resid_block * | rb | ) |
check_resid_block
ptr_resid_block | *rb |
CHECK_RESID_BLOCK(rb) Explore a residuation block.
Definition at line 965 of file memory.c.
References check_goal_stack(), check_resid_list(), LONELY, and unchecked().
|
static |
|
static |
check_resid_list
ptr_resid_list | *l |
CHECK_RESID_LIST Update all the values in the list of residuation variables, which is a list of pairs of psi_terms.
Definition at line 1252 of file memory.c.
References check_psi_term(), and unchecked().
|
static |
check_special_addresses
CHECK_SPECIAL_ADDRESSES Here we check all the addresses which do not point to a whole data structure, but to something within, for example a field such as VALUE which might have been modified in a PSI_TERM structure. These are the LONELY addresses.
Definition at line 1202 of file memory.c.
References wl_stack::aaaa_3, wl_stack::bbbb_3, choice_stack, cut_ptr, LONELY, wl_stack::next, wl_choice_point::next, wl_choice_point::stack_top, wl_stack::type, unchecked(), undo_action, undo_stack, and VALID_RANGE.
|
static |
check_string
GENERIC | *s |
CHECK_STRING(s) Claim the memory used by the string S.
Definition at line 405 of file memory.c.
References delta, LONELY, MAX_BUILT_INS, pass, and unchecked().
|
static |
check_symbol
ptr_node | *n |
CHECK_SYMBOL This goes through the symbol table, checking all nodes, symbols, strings and definitions not contained in the type table.
Definition at line 764 of file memory.c.
References check_keyword(), check_string(), and unchecked().
|
static |
check_triple_list
ptr_triple_list | *p |
CHECK_TRIPLE_LIST Checks a list of <GOAL,BODY,DEF> triples.
Definition at line 517 of file memory.c.
References check_definition(), check_psi_term(), and unchecked().
|
static |
check_type_disj
ptr_int_list | *p |
CHECK_TYPE_DISJ Checks the list of definitions appearing in a type disjunction.
Definition at line 782 of file memory.c.
References check_definition(), and unchecked().
|
static |
|
static |
check_undo_stack
ptr_stack | *s |
CHECK_UNDO_STACK() This looks after checking the addresses of objects pointed to in the trail. The type of the pointer to be restored on backtracking is known, which allows the structure it is referring to to be accordingly checked.
Definition at line 1113 of file memory.c.
References check_code(), check_definition(), check_goal_stack(), check_psi_term(), check_resid(), code_ptr, cut_ptr, def_ptr, destroy_window, goal_ptr, hide_window, int_ptr, psi_term_ptr, resid_ptr, show_window, and unchecked().
|
static |
check_var | |
ptr_node | *n |
CHECK_VAR(t) Go through the VARiable tree. (This could be made tail recursive.)
Definition at line 1270 of file memory.c.
References check_psi_term(), check_string(), and unchecked().
|
static |
compress
COMPRESS() This routine compresses the memory contents and calculates the new addresses. First the Stack is compressed, bottom up. Secondly the Heap is compressed, top down.
Definition at line 222 of file memory.c.
References ALIGN, assert, delta, heap_pointer, LONELY, mem_base, mem_limit, other_pointer, stack_pointer, TRUE, and VALID_ADDRESS.
void fail_all | ( | ) |
fail_all
FAIL_ALL() This routines provokes a total failure, in case of a bad error (out of memory, abort, etc...). All goals are abandoned.
Definition at line 188 of file memory.c.
References abort_life(), choice_stack, goal_stack, NULL, open_input_file(), output_stream, stdin_cleareof(), TRUE, and undo_stack.
void garbage | ( | ) |
garbage
GARBAGE() The garbage collector. This routine is called whenever memory is getting low. It returns TRUE if insufficient memory was freed to allow the interpreter to carry on working.
This is a half-space GC, it first explores all known structures, then compresses the heap and the stack, then during the second pass assigns all the new addresses.
Bugs will appear if the collector is called during parsing or other such routines which are 'unsafe'. In order to avoid this problem, before one of these routines is invoked the program will check to see whether there is enough memory available to work, and will call the GC if not (this is a fix, because it is not possible to determine in advance what the size of a psi_term read by the parser will be).
Definition at line 1529 of file memory.c.
References assert, bounds_undo_stack(), check(), clear_copy(), compress(), FALSE, garbage_time, gc_time, heap_pointer, ignore_eff, last_garbage_time, life_time, mem_base, mem_limit, NULL, other_base, other_limit, pass, pointer_names, print_gc_info(), printed_pointers, stack_info(), stack_pointer, TRUE, and verbose.
int GetBoolOption | ( | char * | name | ) |
GetBoolOption.
char | *name |
Definition at line 64 of file memory.c.
References GetStrOption().
int GetIntOption | ( | char * | name, |
int | def | ||
) |
GetIntOption.
char | *name |
int | def |
Definition at line 78 of file memory.c.
References GetStrOption().
char* GetStrOption | ( | char * | name, |
char * | def | ||
) |
GENERIC heap_alloc | ( | long | s | ) |
heap_alloc
long | s |
HEAP_ALLOC(s) This returns a pointer to S bytes of memory in the heap. Alignment is taken into account in the following manner: the macro ALIGN is supposed to be a power of 2 and the pointer returned is a multiple of ALIGN.
Definition at line 1616 of file memory.c.
References ALIGN, Errorline(), heap_pointer, and stack_pointer.
void init_memory | ( | ) |
init_memory ()
INIT_MEMORY() Get two big blocks of memory to work in. The second is only used for the half-space garbage collector. The start and end addresses of the blocks are re-aligned correctly. to allocate.
Definition at line 1671 of file memory.c.
References ALIGNUP, alloc_words, ALLOC_WORDS, buffer, delta, Errorline(), GetIntOption(), heap_pointer, mem_base, mem_limit, mem_size, other_base, other_limit, other_pointer, PRINT_BUFFER, and stack_pointer.
long memory_check | ( | ) |
memory_check
MEMORY_CHECK() This function tests to see whether enough memory is available to allow execution to continue. It causes a garbage collection if not, and if that fails to release enough memory it returns FALSE.
Definition at line 1723 of file memory.c.
References fail_all(), FALSE, garbage(), GC_THRESHOLD, heap_pointer, stack_pointer, TRUE, and verbose.
void pchoices | ( | ) |
pchoices
for debugging
Definition at line 93 of file memory.c.
References choice_stack, wl_choice_point::next, stack_pointer, and wl_choice_point::stack_top.
void print_gc_info | ( | long | timeflag | ) |
print_gc_info
long | timeflag |
Definition at line 1492 of file memory.c.
References gc_time, heap_pointer, life_time, mem_base, mem_limit, mem_size, and stack_pointer.
void print_undo_stack | ( | ) |
print_undo_stack
Definition at line 121 of file memory.c.
References wl_stack::aaaa_3, wl_stack::bbbb_3, mem_base, mem_limit, wl_stack::next, wl_stack::type, and undo_stack.
GENERIC stack_alloc | ( | long | s | ) |
stack_alloc
long | s |
STACK_ALLOC(s) This returns a pointer to S bytes of memory in the stack. Alignment is taken into account in the following manner: the macro ALIGN is supposed to be a power of 2 and the pointer returned is a multiple of ALIGN.
Definition at line 1642 of file memory.c.
References ALIGN, Errorline(), heap_pointer, and stack_pointer.
|
static |
unchecked
GENERIC | *p |
long | len |
UNCHECKED(p,l) P is a pointer to a structure L bytes in length. If L=LONELY then that means that P is a pointer to a sub-field of a structure. The function returns TRUE if the structure has not been yet thoroughly explored, otherwise FALSE. If this is the second pass then it translates P to its new value (as calculated by COMPRESS).
Definition at line 338 of file memory.c.
References assert, delta, Errorline(), FALSE, LONELY, MAX_BUILT_INS, pass, TRUE, and VALID_ADDRESS.