[m-dev.] for review: shut up a warning

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Jan 19 13:59:22 AEDT 2001


On 19-Jan-2001, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> On 19-Jan-2001, Zoltan Somogyi <zs at cs.mu.OZ.AU> wrote:
> > On 18-Jan-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> > > That code has a memory leak in non-conservative GC grades.
> > > In non-conservative GC grades, the memory will get allocated
> > > with malloc(), and never freed.  It should instead get
> > > allocated on the Mercury heap, so that it will get
> > > reclaimed on backtracking (or by the accurate garbage
> > > collector, when that is implemented).
> > > 
> > > That's why the code should use MR_make_string(), as I suggested
> > > earlier.
> > 
> > Fergus, MR_make_string doesn't do what you think it does. I will change the
> > code to call MR_make_aligned_string_copy.
> 
> Actually, I can't do *only* that. This address of this string goes into a
> structure that currently gets allocated with MR_GC_NEW; following your
> suggestion would leave a dangling pointer.

Oh, I see.  Well, it would be an unreachable dangling pointer ;-)
But you're right, that is a problem -- the code you added to allocate
the closure layout using MR_GC_NEW is another memory leak for
non-conservative GC grades.

> 
> browser/dl.m:
> 	Allocate all memory for closure layouts on the heap.
> 
> runtime/mercury_heap.h:
> 	Define two macros for allocating a structure on the heap.
> 
> runtime/mercury_stacks.h:
> runtime/mercury_types.h:
> 	Move the macro MR_bytes_to_words from mercury_stacks.h to
> 	mercury_types.h, to make it accessible to mercury_heap.h.

s/on the heap/on the Mercury heap/g

The log message should explain why the closure layouts need to be
allocated on the Mercury heap.  A summary at the top of the log
message would also be helpful.

> cvs diff: Diffing browser/
> Index: browser//dl.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/browser/dl.m,v
> retrieving revision 1.7
> diff -u -b -r1.7 dl.m
> --- browser//dl.m	2001/01/18 01:18:25	1.7
> +++ browser//dl.m	2001/01/19 02:16:04
> @@ -189,7 +190,12 @@
>  	ML_DL_closure_counter++;
>  	sprintf(buf, ""@%d;"", ML_DL_closure_counter);
>  
> -	closure_id = MR_GC_NEW(MR_Closure_Id);
> +	/*
> +	** XXX All the allocations in this code should use malloc
> +	** in deep profiling grades.
> +	*/
> +
> +	MR_incr_hp_type(closure_id, MR_Closure_Id);
>  	closure_id->proc_id.MR_proc_user.MR_user_pred_or_func = MR_PREDICATE;
>  	closure_id->proc_id.MR_proc_user.MR_user_decl_module = ""unknown"";
>  	closure_id->proc_id.MR_proc_user.MR_user_def_module = ""unknown"";
> @@ -199,9 +205,9 @@
>  	closure_id->module_name = ""dl"";
>  	closure_id->file_name = __FILE__;
>  	closure_id->line_number = __LINE__;
> -	closure_id->goal_path = strdup(buf);
> +	closure_id->goal_path = MR_make_aligned_string_copy(buf);
>  
> -	closure_layout = MR_GC_NEW(MR_Closure_Dyn_Link_Layout);
> +	MR_incr_hp_type(closure_layout, MR_Closure_Dyn_Link_Layout);
>  	closure_layout->closure_id = closure_id;
>  	closure_layout->type_params = NULL;
>  	closure_layout->num_all_args = 0;

This code ought to use MR_incr_hp_type_msg() rather than
MR_incr_hp_type(), so that the allocations show up in the heap
allocation profiler.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list