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

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri Jan 19 13:26:09 AEDT 2001


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.

The structure and the string should be allocated using the same mechanism.
That mechanism should be incr_hp_* for now. However, Tom should change both
allocations to use malloc when deep profiling is enabled, since the call graph
is permanent and may contain pointers to closure layouts.

The new Log and diff follow.

Zoltan.

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.

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;
cvs diff: Diffing runtime/
Index: runtime//mercury_heap.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_heap.h,v
retrieving revision 1.19
diff -u -b -r1.19 mercury_heap.h
--- runtime//mercury_heap.h	2001/01/10 10:57:25	1.19
+++ runtime//mercury_heap.h	2001/01/19 02:14:22
@@ -1,5 +1,5 @@
 /*
-** Copyright (C) 1995-2000 The University of Melbourne.
+** Copyright (C) 1995-2001 The University of Melbourne.
 ** This file may only be copied under the terms of the GNU Library General
 ** Public License - see the file COPYING.LIB in the Mercury distribution.
 */
@@ -116,13 +116,15 @@
   ** min_heap_reclamation_point. See the comments in mercury_context.h next to
   ** the set_min_heap_reclamation_point() macro.
   */
-  #define	MR_restore_hp(src)	(				\
+  #define MR_restore_hp(src)						\
+		(							\
   			MR_LVALUE_CAST(MR_Word, MR_hp) = (src),		\
   			(void) 0					\
   		)
 
   /*
-  #define	MR_restore_hp(src)	(				\
+  #define	MR_restore_hp(src)					\
+  		(							\
   			MR_LVALUE_CAST(MR_Word, MR_hp) =		\
   			  ( (MR_Word) MR_min_hp_rec < (src) ?		\
   			  (src) : (MR_Word) MR_min_hp_rec ),		\
@@ -174,6 +176,13 @@
 		MR_tag_incr_hp_atomic((dest), MR_mktag(0), (count))
 #define	MR_incr_hp_atomic_msg(dest, count, proclabel, type) \
 		MR_tag_incr_hp_atomic_msg((dest), MR_mktag(0), (count), \
+			proclabel, (type))
+#define	MR_incr_hp_type(dest, typename)					\
+		MR_tag_incr_hp((dest), MR_mktag(0),			\
+			(MR_bytes_to_words(sizeof(typename))))
+#define	MR_incr_hp_type_msg(dest, typename, proclabel, type)		\
+		MR_tag_incr_hp_msg((dest), MR_mktag(0),			\
+			(MR_bytes_to_words(sizeof(typename))),		\
 			proclabel, (type))
 
 #ifdef MR_HIGHLEVEL_CODE
Index: runtime//mercury_stacks.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_stacks.h,v
retrieving revision 1.27
diff -u -b -r1.27 mercury_stacks.h
--- runtime//mercury_stacks.h	2001/01/10 10:57:25	1.27
+++ runtime//mercury_stacks.h	2001/01/19 02:11:11
@@ -125,9 +125,6 @@
 				MR_nondstack_overflow_check();		\
 			} while (0)
 
-/* convert a size in bytes to a size in words, rounding up if necessary */
-#define MR_bytes_to_words(x) (((x) + sizeof(MR_Word) - 1) / sizeof(MR_Word))
-
 /* just like mkframe, but also reserves space for a struct     */
 /* with the given tag at the bottom of the nondet stack frame  */
 #define	MR_mkpragmaframe(predname, numslots, structname, redoip)	\
Index: runtime//mercury_types.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_types.h,v
retrieving revision 1.25
diff -u -b -r1.25 mercury_types.h
--- runtime//mercury_types.h	2000/12/04 04:48:05	1.25
+++ runtime//mercury_types.h	2001/01/19 02:13:25
@@ -60,6 +60,12 @@
 typedef	MR_intptr_t		MR_Bool;
 
 /*
+** Convert a size in bytes to a size in words, rounding up if necessary.
+*/
+
+#define MR_bytes_to_words(x)	(((x) + sizeof(MR_Word) - 1) / sizeof(MR_Word))
+
+/*
 ** `MR_Code *' is used as a generic pointer-to-label type that can point
 ** to any label defined using the Define_* macros in mercury_goto.h.
 */
@@ -109,12 +115,11 @@
 ** Since it is used in some C code fragments, we define it as MR_Word
 ** in the low-level backend.
 */
+
 #ifdef MR_HIGHLEVEL_CODE
 typedef void 	*MR_Box;
 #else
 typedef MR_Word MR_Box;
 #endif
-
-
 
 #endif /* not MERCURY_TYPES_H */
cvs diff: Diffing runtime//GETOPT
cvs diff: Diffing runtime//machdeps
--------------------------------------------------------------------------
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