mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-15 05:44:58 +00:00
Estimated hours taken: 0.25 Branches: main compiler/notes/gc_and_c_code.html: Clarify that this file only applies to the LLDS back-end.
76 lines
1.6 KiB
HTML
76 lines
1.6 KiB
HTML
<html>
|
|
<head>
|
|
<title>
|
|
Information On LLDS Accurate Garbage Collection And C Code
|
|
</title>
|
|
</head>
|
|
|
|
<body
|
|
bgcolor="#ffffff"
|
|
text="#000000"
|
|
>
|
|
|
|
<hr>
|
|
<!-------------------------->
|
|
|
|
When handwritten code is called from Mercury, the garbage collection
|
|
scheduler doesn't know anything about the code, so it cannot replace
|
|
the succip on the stack (if there is one) with the collector's address.
|
|
|
|
<p>
|
|
|
|
If the handwritten code calls no other code, then this is fine, the
|
|
scheduler knows it can replace the succip variable and when a
|
|
proceed() occurs execution will return to mercury code which it
|
|
knows about.
|
|
|
|
<p>
|
|
|
|
If handwritten code calls other handwritten code, we have a problem,
|
|
as succip will be saved on the stack and we don't know where on
|
|
the stack it is stored. So we use a global variable 'saved_succip' which
|
|
is succip is saved into. Care must be taken to save saved_succip on the
|
|
stack so it doesn't get clobbered. <br>
|
|
So
|
|
<pre>
|
|
detstackvar(1) = (int) succip;
|
|
</pre>
|
|
becomes
|
|
<pre>
|
|
detstackvar(1) = (int) saved_succip;
|
|
saved_succip = (int) succip;
|
|
</pre>
|
|
|
|
and, when restoring,
|
|
<pre>
|
|
succip = (int) detstackvar(1);
|
|
</pre>
|
|
becomes
|
|
<pre>
|
|
succip = saved_succip;
|
|
saved_succip = detstackvar(1);
|
|
</pre>
|
|
|
|
(With appropriate LVALUE_CASTs).
|
|
|
|
<p>
|
|
|
|
In this way, garbage collection always knows where the succip is stored
|
|
in handwritten code.
|
|
|
|
<p>
|
|
|
|
The garbage collection code must check that the current execution is not
|
|
still in a handwritten predicate - if it is, it must re-schedule (essentially
|
|
just the same as before).
|
|
|
|
<p>
|
|
|
|
|
|
<hr>
|
|
<!-------------------------->
|
|
|
|
Last update was $Date: 2003-11-05 08:42:10 $ by $Author: fjh $@cs.mu.oz.au. <br>
|
|
</body>
|
|
</html>
|