Article View: comp.lang.prolog
Article #72Re: Unsafe variables
From: Bart Demoen
Date: Fri, 07 Aug 1992 15:55
Date: Fri, 07 Aug 1992 15:55
46 lines
2416 bytes
2416 bytes
In <1992Jul28.072501.6238@sics.se> Mats Carlsson writes:
> I don't know how other WAM based Prologs do it, but in SICStus Prolog,
> the compiler ensures that all permanent variables are initialized at
> the first 'call' instruction of every clause. The variables are initialized
> by 'put_variable' if they are not otherwise initialized already.
> This is done to prevent there from being random bit patterns in the
> permanent variables in the event of a garbage collection.
Garbage collection has to deal with 3 types of permanent variables
initialized and active (1)
initialized and no longer active (2)
not yet initialized (3)
(1) poses no problem
There are at least three ways to take care of (3):
1. at the first call, initialize the ones that are not yet active;
it is the SICStus solution Mats described
2. make info available to the gc process so that it knows which permanent
vars are active --> no need to initialize the non active ones
it is the ProLog by BIM solution
3. let the gc process use the random bit patterns in a carefull way, i.e.
only if they denote reasonable objects - e.g. if a pointer points in a
non-active part of the heap, do not follow it - ; in this way, gc marks more
than non-garbage, in fact it should be possible to write a program that
attempts gc and recovers nothing while other schemas would collect
something
it is, as far as I know, the Quintus solution
(2) is dealt with in systems with trimming by making the length of the
environment somehow available to the gc process, often by storing
this length in *(CP-1)
SICStus does not trim environments, so perhaps it doesn't collect all garbage ?
> I don't have any figures, but I suspect that variables created by this
> mechanism would significantly contribute to the heap growth if one
> gets rid of unsafe variables.
Getting rid of unitialized variables by a globalizing put_variable,
seems indeed a bad idea.
Bart Demoen
Technical Details
Message-ID:
<1992Aug7.155554.9342@cs.kuleuven.ac.be>Path:
arc1-ca.pugleaf.net!sparky!uunet!mcsun!ub4b!news.cs.kuleuven.ac.be!bimbartShow Full Headers
Complete Article Headers
Newsgroups: comp.lang.prolog Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!ub4b!news.cs.kuleuven.ac.be!bimbart From: bimbart@cs.kuleuven.ac.be (Bart Demoen) Subject: Re: Unsafe variables Message-ID: <1992Aug7.155554.9342@cs.kuleuven.ac.be> Sender: news@cs.kuleuven.ac.be Nntp-Posting-Host: hera.cs.kuleuven.ac.be Organization: Dept. Computerwetenschappen K.U.Leuven Date: Fri, 7 Aug 1992 15:55:54 GMT Lines: 47