[m-rev.] for review: fix bugs in mercury_deep_profiling.c

Zoltan Somogyi zs at cs.mu.OZ.AU
Tue Apr 19 18:25:17 AEST 2005


For post-commit review by Julien. Any odd indentation is from diff -b.

Zoltan.

runtime/mercury_deep_profiling.c:
	Fix two bugs in the code that writes out Deep.data. This required
	improving the infrastructure for debugging this module.

	The first bug involved the management of the table that mapped
	the addresses of proc_layout structures (which point to proc statics)
	to numerical ids. Of the three places that inserted into this table,
	one inserted the address of the proc static structure directly,
	leaving dangling proc static ids (ids that don't refer to anything)
	in the generated Deep.data file. This caused mdprof to abort
	when processing the Deep.data file.

	To make such bugs less likely in the future, provide type-safe
	interface functions to the main functions for manipulating hash tables.

	The second bug was effectively invisible: the "written" flag wasn't
	set on call site dynamic structures as they were written out.

	Convert the module to four-space indentation to reduce the number of
	bad line breaks.

cvs diff: Diffing .
cvs diff: Diffing analysis
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/doc
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curs
cvs diff: Diffing extras/curs/samples
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/error
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_glut
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/gears
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/moose/tests
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/quickcheck
cvs diff: Diffing extras/quickcheck/tutes
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing extras/xml/samples
cvs diff: Diffing extras/xml_stylesheets
cvs diff: Diffing java
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing mdbcomp
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
Index: runtime/mercury_deep_profiling.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_deep_profiling.c,v
retrieving revision 1.15
diff -u -b -r1.15 mercury_deep_profiling.c
--- runtime/mercury_deep_profiling.c	23 May 2004 22:16:50 -0000	1.15
+++ runtime/mercury_deep_profiling.c	19 Apr 2005 07:20:51 -0000
@@ -1,4 +1,7 @@
 /*
+** vim:sw=4 ts=4 expandtab
+*/
+/*
 ** Copyright (C) 2001-2004 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.
@@ -100,8 +103,7 @@
 MR_CallSiteDynamic	*MR_current_call_site_dynamic =
 				&MR_main_grandparent_call_site_dynamic;
 MR_CallSiteDynamic	*MR_next_call_site_dynamic = NULL;
-MR_CallSiteDynList	**MR_current_callback_site =
-				(MR_CallSiteDynList **)
+MR_CallSiteDynList  **MR_current_callback_site = (MR_CallSiteDynList **)
 				&MR_main_parent_call_site_dynamics[0];
 volatile MR_bool 	MR_inside_deep_profiling_code = MR_FALSE;
 volatile unsigned	MR_quanta_inside_deep_profiling_code = 0;
@@ -182,8 +184,7 @@
 	while (csd_list != NULL)
 	{
 		if (csd_list->MR_csdlist_key == entry) {
-			MR_next_call_site_dynamic =
-				csd_list->MR_csdlist_call_site;
+            MR_next_call_site_dynamic = csd_list->MR_csdlist_call_site;
 #ifdef	MR_DEEP_PROFILING_STATISTICS
 			MR_deep_prof_prep_callback_old++;
 #endif
@@ -247,6 +248,7 @@
 */
 
 static	void	MR_deep_data_output_error(const char *msg);
+static  void    MR_write_out_profiling_tree_check_unwritten(FILE *check_fp);
 
 static	void	MR_write_out_id_string(FILE *fp);
 
@@ -262,6 +264,11 @@
 static	void	MR_write_out_ho_call_site_nodes(FILE *fp,
 			MR_CallSiteDynList *dynlist);
 
+static  void    MR_unwritten_css_handler(FILE *fp, const void *css);
+static  void    MR_unwritten_csd_handler(FILE *fp, const void *csd);
+static  void    MR_unwritten_pl_handler(FILE *fp, const void *ps);
+static  void    MR_unwritten_pd_handler(FILE *fp, const void *pd);
+
 typedef enum node_kind {
 	kind_csd, kind_pd, kind_css, kind_ps
 } MR_NodeKind;
@@ -297,19 +304,37 @@
 } MR_ProfilingHashTable;
 
 static	MR_ProfilingHashTable	*MR_create_hash_table(int size);
-static	MR_bool			MR_hash_table_insert(
-					MR_ProfilingHashTable *table,
-					const void *ptr,
-					int *id, MR_bool *already_written,
+
+static  MR_bool                 MR_insert_proc_layout(
+                                    const MR_Proc_Layout *pl, int *id,
+                                    MR_bool *already_written,
 					MR_bool init_written);
-static	void			MR_hash_table_flag_written(
-					MR_ProfilingHashTable *table,
-					const void *ptr);
+static  MR_bool                 MR_insert_proc_dynamic(
+                                    const MR_ProcDynamic *pd, int *id,
+                                    MR_bool *already_written,
+                                    MR_bool init_written);
+static  MR_bool                 MR_insert_call_site_static(
+                                    const MR_CallSiteStatic *css, int *id,
+                                    MR_bool *already_written,
+                                    MR_bool init_written);
+static  MR_bool                 MR_insert_call_site_dynamic(
+                                    const MR_CallSiteDynamic *csd, int *id,
+                                    MR_bool *already_written,
+                                    MR_bool init_written);
+
+static  void                    MR_flag_written_proc_layout(
+                                    const MR_Proc_Layout *pl);
+static  void                    MR_flag_written_proc_dynamic(
+                                    const MR_ProcDynamic *pd);
+static  void                    MR_flag_written_call_site_static(
+                                    const MR_CallSiteStatic *css);
+static  void                    MR_flag_written_call_site_dynamic(
+                                    const MR_CallSiteDynamic *csd);
 
 static	MR_ProfilingHashTable	*MR_call_site_dynamic_table;
 static	MR_ProfilingHashTable	*MR_call_site_static_table;
 static	MR_ProfilingHashTable	*MR_proc_dynamic_table;
-static	MR_ProfilingHashTable	*MR_proc_static_table;
+static  MR_ProfilingHashTable   *MR_proc_layout_table;
 
 /*----------------------------------------------------------------------------*/
 /*----------------------------------------------------------------------------*/
@@ -342,6 +367,7 @@
 	int			root_pd_id;
 	FILE			*fp;
 	int			ticks_per_sec;
+    FILE                    *check_fp;
 
 	fp = fopen(MR_MDPROF_DATAFILENAME, "wb+");
 	if (fp == NULL) {
@@ -379,13 +405,12 @@
 	MR_call_site_dynamic_table = MR_create_hash_table(MR_hash_table_size);
 	MR_call_site_static_table  = MR_create_hash_table(MR_hash_table_size);
 	MR_proc_dynamic_table = MR_create_hash_table(MR_hash_table_size);
-	MR_proc_static_table  = MR_create_hash_table(MR_hash_table_size);
+    MR_proc_layout_table  = MR_create_hash_table(MR_hash_table_size);
 
-	if (MR_hash_table_insert(MR_proc_dynamic_table,
-		&MR_main_parent_proc_dynamic, &root_pd_id, NULL, MR_FALSE))
+    if (MR_insert_proc_dynamic(&MR_main_parent_proc_dynamic, &root_pd_id,
+        NULL, MR_FALSE))
 	{
-		MR_fatal_error(
-			"MR_write_out_profiling_tree: root seen before");
+        MR_fatal_error("MR_write_out_profiling_tree: root seen before");
 	}
 
 #ifdef MR_DEEP_PROFILING_DEBUG
@@ -412,7 +437,7 @@
 	MR_write_fixed_size_int(fp, MR_call_site_dynamic_table->last_id);
 	MR_write_fixed_size_int(fp, MR_call_site_static_table->last_id);
 	MR_write_fixed_size_int(fp, MR_proc_dynamic_table->last_id);
-	MR_write_fixed_size_int(fp, MR_proc_static_table->last_id);
+    MR_write_fixed_size_int(fp, MR_proc_layout_table->last_id);
 
 	if (fclose(fp) != 0) {
 		MR_deep_data_output_error("cannot close");
@@ -566,19 +591,25 @@
 	fprintf(stderr, "\nClosure search length histogram:\n");
 	for (i = 0; i < MR_MAX_CLOSURE_LIST_LENGTH; i++) {
 		if (MR_closure_search_lengths[i] > 0) {
-			fprintf(stderr, "\t%3d: %12d\n", i,
-				MR_closure_search_lengths[i]);
+            fprintf(stderr, "\t%3d: %12d\n", i, MR_closure_search_lengths[i]);
 		}
 	}
 
 	fprintf(stderr, "\nMethod search length histogram:\n");
 	for (i = 0; i < MR_MAX_CLOSURE_LIST_LENGTH; i++) {
 		if (MR_method_search_lengths[i] > 0) {
-			fprintf(stderr, "\t%3d: %12d\n", i,
-				MR_method_search_lengths[i]);
+            fprintf(stderr, "\t%3d: %12d\n", i, MR_method_search_lengths[i]);
 		}
 	}
 #endif
+
+#ifdef MR_DEEP_PROFILING_DEBUG
+    check_fp = debug_fp;
+#else
+    check_fp = NULL;
+#endif
+
+    MR_write_out_profiling_tree_check_unwritten(check_fp);
 }
 
 static void
@@ -636,18 +667,40 @@
 		MR_fatal_error("MR_write_out_proc_static: null proc_layout");
 	}
 
+    if (! MR_PROC_LAYOUT_HAS_PROC_ID(proc_layout)) {
+        MR_fatal_error("MR_write_out_proc_static: no proc_id\n");
+    }
+
 	ps = proc_layout->MR_sle_proc_static;
 	if (ps == NULL) {
+        procid = &proc_layout->MR_sle_proc_id;
+        if (MR_PROC_ID_IS_UCI(*procid)) {
+            fprintf(stderr, "uci %s/%s/%s/%s/%d/%d\n",
+                procid->MR_proc_uci.MR_uci_type_name,
+                procid->MR_proc_uci.MR_uci_type_module,
+                procid->MR_proc_uci.MR_uci_def_module,
+                procid->MR_proc_uci.MR_uci_pred_name,
+                procid->MR_proc_uci.MR_uci_type_arity,
+                procid->MR_proc_uci.MR_uci_mode);
+        } else {
+            fprintf(stderr, "user %d/%s/%s/%s/%d/%d\n",
+                procid->MR_proc_user.MR_user_pred_or_func,
+                procid->MR_proc_user.MR_user_decl_module,
+                procid->MR_proc_user.MR_user_def_module,
+                procid->MR_proc_user.MR_user_name,
+                procid->MR_proc_user.MR_user_arity,
+                procid->MR_proc_user.MR_user_mode);
+        }
+
 		MR_fatal_error("MR_write_out_proc_static: null ps");
 	}
 
-	(void) MR_hash_table_insert(MR_proc_static_table, proc_layout,
-		&ps_id, &already_written, MR_TRUE);
+    (void) MR_insert_proc_layout(proc_layout, &ps_id, &already_written,
+         MR_TRUE);
 
 #ifdef MR_DEEP_PROFILING_DEBUG
 	if (debug_fp != NULL) {
-		fprintf(debug_fp, "proc_static %p/%p/%d\n",
-			proc_layout, ps, ps_id);
+        fprintf(debug_fp, "proc_static %p/%p/%d\n", proc_layout, ps, ps_id);
 		fprintf(debug_fp, "  filename \"%s\", linenumber %d, "
 			"interface %d, %d call sites\n",
 		ps->MR_ps_file_name, ps->MR_ps_line_number,
@@ -659,7 +712,7 @@
 		MR_fatal_error("MR_write_out_proc_static: seen ps");
 	}
 
-	MR_hash_table_flag_written(MR_proc_static_table, proc_layout);
+    MR_flag_written_proc_layout(proc_layout);
 
 	MR_write_byte(fp, MR_deep_token_proc_static);
 	MR_write_ptr(fp, kind_ps, ps_id);
@@ -668,7 +721,7 @@
 	if (MR_PROC_ID_IS_UCI(*procid)) {
 #ifdef MR_DEEP_PROFILING_DEBUG
 		if (debug_fp != NULL) {
-			fprintf(debug_fp, "  compiler %s/%s/%s/%s/%d/%d\n",
+            fprintf(debug_fp, "  uci %s/%s/%s/%s/%d/%d\n",
 				procid->MR_proc_uci.MR_uci_type_name,
 				procid->MR_proc_uci.MR_uci_type_module,
 				procid->MR_proc_uci.MR_uci_def_module,
@@ -698,8 +751,7 @@
 		}
 #endif
 
-		if (procid->MR_proc_user.MR_user_pred_or_func == MR_PREDICATE)
-		{
+        if (procid->MR_proc_user.MR_user_pred_or_func == MR_PREDICATE) {
 			MR_write_byte(fp, MR_deep_token_isa_predicate);
 		} else {
 			MR_write_byte(fp, MR_deep_token_isa_function);
@@ -718,14 +770,13 @@
 	MR_write_num(fp, ps->MR_ps_num_call_sites);
 
 	for (i = 0; i < ps->MR_ps_num_call_sites; i++) {
-		(void) MR_hash_table_insert(MR_call_site_static_table,
-			&ps->MR_ps_call_sites[i], &css_id, NULL, MR_FALSE);
+        (void) MR_insert_call_site_static(&ps->MR_ps_call_sites[i], &css_id,
+            NULL, MR_FALSE);
 
 #ifdef MR_DEEP_PROFILING_DEBUG
 		if (debug_fp != NULL) {
 			fprintf(debug_fp,
-				"call site id %d in "
-				"proc_static %p/%p/%d -> %d\n",
+                "call site id %d in proc_static %p/%p/%d -> %d\n",
 				i, proc_layout, ps, ps_id, css_id);
 		}
 #endif
@@ -736,8 +787,7 @@
 	for (i = 0; i < ps->MR_ps_num_call_sites; i++) {
 #ifdef MR_DEEP_PROFILING_DEBUG
 		if (debug_fp != NULL) {
-			fprintf(debug_fp,
-				"in proc_static %p/%p/%d, call site %d\n",
+            fprintf(debug_fp, "in proc_static %p/%p/%d, call site %d\n",
 				proc_layout, ps, ps_id, i);
 		}
 #endif
@@ -757,21 +807,20 @@
 		MR_fatal_error("MR_write_out_call_site_static: null css");
 	}
 
-	(void) MR_hash_table_insert(MR_call_site_static_table, css,
-		&css_id, &already_written, MR_TRUE);
+    (void) MR_insert_call_site_static(css, &css_id, &already_written, MR_TRUE);
 
 	if (already_written) {
 		MR_fatal_error("MR_write_out_call_site_static: seen css");
+        fflush(fp);
 	}
 
-	MR_hash_table_flag_written(MR_call_site_static_table, css);
+    MR_flag_written_call_site_static(css);
 
 #ifdef MR_DEEP_PROFILING_DEBUG
 	if (debug_fp != NULL) {
 		fprintf(debug_fp, "call_site_static %p/%d\n", css, css_id);
 		fprintf(debug_fp,
-			"  filename \"%s\", linenum %d, "
-			"goal path %s, kind %d\n",
+            "  filename \"%s\", linenum %d, goal path %s, kind %d\n",
 		css->MR_css_file_name, css->MR_css_line_number,
 		css->MR_css_goal_path, css->MR_css_kind);
 	}
@@ -781,9 +830,8 @@
 	MR_write_ptr(fp, kind_css, css_id);
 	MR_write_kind(fp, css->MR_css_kind);
 	if (css->MR_css_kind == MR_normal_call) {
-		(void) MR_hash_table_insert(MR_proc_static_table,
-			css->MR_css_callee_ptr_if_known,
-			&ps_id, NULL, MR_FALSE);
+        (void) MR_insert_proc_layout(css->MR_css_callee_ptr_if_known, &ps_id,
+            NULL, MR_FALSE);
 #ifdef MR_DEEP_PROFILING_DEBUG
 		if (debug_fp != NULL) {
 			fprintf(debug_fp, "  callee %p/%d\n",
@@ -792,8 +840,7 @@
 #endif
 		MR_write_num(fp, ps_id);
 		if (css->MR_css_type_subst_if_known != NULL) {
-			MR_write_string(fp,
-				css->MR_css_type_subst_if_known);
+            MR_write_string(fp, css->MR_css_type_subst_if_known);
 		} else {
 			MR_write_string(fp, "");
 		}
@@ -822,26 +869,24 @@
 
 #ifdef MR_DEEP_PROFILING_DEBUG
 	if (debug_fp != NULL) {
-		fprintf(debug_fp,
-			"call_site_dynamic %p: callee proc_dynamic %p\n",
+        fprintf(debug_fp, "call_site_dynamic %p: callee proc_dynamic %p\n",
 		csd, csd->MR_csd_callee_ptr);
 	}
 #endif
 
 	MR_write_byte(fp, MR_deep_token_call_site_dynamic);
-	if (! MR_hash_table_insert(MR_call_site_dynamic_table, csd,
-		&csd_id, NULL, MR_TRUE))
-	{
-		MR_fatal_error(
-			"MR_write_out_call_site_dynamic: insert succeeded");
+    if (! MR_insert_call_site_dynamic(csd, &csd_id, NULL, MR_FALSE)) {
+        MR_fatal_error("MR_write_out_call_site_dynamic: insert succeeded");
 	}
 
+    MR_flag_written_call_site_dynamic(csd);
+
 	MR_write_ptr(fp, kind_csd, csd_id);
 	if (csd->MR_csd_callee_ptr == NULL) {
 		pd_id = 0;
 	} else {
-		(void) MR_hash_table_insert(MR_proc_dynamic_table,
-			csd->MR_csd_callee_ptr, &pd_id, NULL, MR_FALSE);
+        (void) MR_insert_proc_dynamic(csd->MR_csd_callee_ptr, &pd_id, NULL,
+            MR_FALSE);
 	}
 
 	MR_write_ptr(fp, kind_pd, pd_id);
@@ -853,56 +898,72 @@
 
 #ifdef MR_DEEP_PROFILING_PORT_COUNTS
   #ifdef MR_DEEP_PROFILING_EXPLICIT_CALL_COUNTS
-	if (csd->MR_csd_own.MR_own_calls != 0)
+    if (csd->MR_csd_own.MR_own_calls != 0) {
 		bitmask |= 0x0001;
+    }
   #endif
-	if (csd->MR_csd_own.MR_own_exits != 0)
+    if (csd->MR_csd_own.MR_own_exits != 0) {
 		bitmask |= 0x0002;
-	if (csd->MR_csd_own.MR_own_fails != 0)
+    }
+    if (csd->MR_csd_own.MR_own_fails != 0) {
 		bitmask |= 0x0004;
-	if (csd->MR_csd_own.MR_own_redos != 0)
+    }
+    if (csd->MR_csd_own.MR_own_redos != 0) {
 		bitmask |= 0x0008;
-	if (csd->MR_csd_own.MR_own_excps != 0)
+    }
+    if (csd->MR_csd_own.MR_own_excps != 0) {
 		bitmask |= 0x0010;
+    }
 #endif
 #ifdef MR_DEEP_PROFILING_TIMING
-	if (csd->MR_csd_own.MR_own_quanta != 0)
+    if (csd->MR_csd_own.MR_own_quanta != 0) {
 		bitmask |= 0x0020;
+    }
 #endif
 #ifdef MR_DEEP_PROFILING_MEMORY
-	if (csd->MR_csd_own.MR_own_allocs != 0)
+    if (csd->MR_csd_own.MR_own_allocs != 0) {
 		bitmask |= 0x0040;
-	if (csd->MR_csd_own.MR_own_words != 0)
+    }
+    if (csd->MR_csd_own.MR_own_words != 0) {
 		bitmask |= 0x0080;
+    }
 #endif
 
 	MR_write_num(fp, bitmask);
 
 #ifdef MR_DEEP_PROFILING_PORT_COUNTS
   #ifdef MR_DEEP_PROFILING_EXPLICIT_CALL_COUNTS
-	if (csd->MR_csd_own.MR_own_calls != 0)
+    if (csd->MR_csd_own.MR_own_calls != 0) {
 		MR_write_num(fp, csd->MR_csd_own.MR_own_calls);
+    }
   #endif
-	if (csd->MR_csd_own.MR_own_exits != 0)
+    if (csd->MR_csd_own.MR_own_exits != 0) {
 		MR_write_num(fp, csd->MR_csd_own.MR_own_exits);
-	if (csd->MR_csd_own.MR_own_fails != 0)
+    }
+    if (csd->MR_csd_own.MR_own_fails != 0) {
 		MR_write_num(fp, csd->MR_csd_own.MR_own_fails);
-	if (csd->MR_csd_own.MR_own_redos != 0)
+    }
+    if (csd->MR_csd_own.MR_own_redos != 0) {
 		MR_write_num(fp, csd->MR_csd_own.MR_own_redos);
-	if (csd->MR_csd_own.MR_own_excps != 0)
+    }
+    if (csd->MR_csd_own.MR_own_excps != 0) {
 		MR_write_num(fp, csd->MR_csd_own.MR_own_excps);
+    }
 #endif
 
 #ifdef MR_DEEP_PROFILING_TIMING
-	if (csd->MR_csd_own.MR_own_quanta != 0)
+    if (csd->MR_csd_own.MR_own_quanta != 0) {
 		MR_write_num(fp, csd->MR_csd_own.MR_own_quanta);
+    }
 #endif
 
 #ifdef MR_DEEP_PROFILING_MEMORY
-	if (csd->MR_csd_own.MR_own_allocs != 0)
+    if (csd->MR_csd_own.MR_own_allocs != 0) {
 		MR_write_num(fp, csd->MR_csd_own.MR_own_allocs);
-	if (csd->MR_csd_own.MR_own_words != 0)
+    }
+    if (csd->MR_csd_own.MR_own_words != 0) {
 		MR_write_num(fp, csd->MR_csd_own.MR_own_words);
+    }
 #endif
 
 	MR_write_out_proc_dynamic(fp, csd->MR_csd_callee_ptr);
@@ -912,6 +973,7 @@
 MR_write_out_proc_dynamic(FILE *fp, const MR_ProcDynamic *pd)
 {
 	const MR_ProcStatic	*ps;
+    const MR_Proc_Layout    *pl;
 	int	pd_id;
 	int	ps_id;
 	MR_bool	already_written;
@@ -926,9 +988,7 @@
 		return;
 	}
 
-	if (! MR_hash_table_insert(MR_proc_dynamic_table, pd,
-		&pd_id, &already_written, MR_TRUE))
-	{
+    if (! MR_insert_proc_dynamic(pd, &pd_id, &already_written, MR_TRUE)) {
 		MR_fatal_error("MR_write_out_proc_dynamic: unseen pd");
 	}
 
@@ -936,11 +996,11 @@
 		return;
 	}
 
-	ps = pd->MR_pd_proc_layout->MR_sle_proc_static;
+    pl = pd->MR_pd_proc_layout;
+    ps = pl->MR_sle_proc_static;
 
-	MR_hash_table_flag_written(MR_proc_dynamic_table, pd);
-	(void) MR_hash_table_insert(MR_proc_static_table, ps, &ps_id,
-		NULL, MR_FALSE);
+    MR_flag_written_proc_dynamic(pd);
+    (void) MR_insert_proc_layout(pl, &ps_id, NULL, MR_FALSE);
 
 #ifdef MR_DEEP_PROFILING_STATISTICS
 	MR_deep_num_pd_nodes++;
@@ -967,14 +1027,11 @@
 #ifdef MR_DEEP_PROFILING_DEBUG
 				if (debug_fp != NULL) {
 					fprintf(debug_fp,
-						"  normal call from pd %p "
-						"to pd %p\n",
-						pd, pd->
-						MR_pd_call_site_ptr_ptrs[i]);
+                        "  normal call from pd %p to pd %p\n",
+                        pd, pd->MR_pd_call_site_ptr_ptrs[i]);
 				}
 #endif
-				MR_write_csd_ptr(fp,
-					pd->MR_pd_call_site_ptr_ptrs[i]);
+                MR_write_csd_ptr(fp, pd->MR_pd_call_site_ptr_ptrs[i]);
 				break;
 
 			case MR_special_call:
@@ -982,8 +1039,7 @@
 			case MR_method_call:
 			case MR_callback:
 				MR_write_out_ho_call_site_ptrs(fp, pd,
-					(MR_CallSiteDynList *)
-					pd->MR_pd_call_site_ptr_ptrs[i]);
+                    (MR_CallSiteDynList *) pd->MR_pd_call_site_ptr_ptrs[i]);
 				break;
 		}
 	}
@@ -1001,8 +1057,7 @@
 			case MR_method_call:
 			case MR_callback:
 				MR_write_out_ho_call_site_nodes(fp,
-					(MR_CallSiteDynList *)
-					pd->MR_pd_call_site_ptr_ptrs[i]);
+                    (MR_CallSiteDynList *) pd->MR_pd_call_site_ptr_ptrs[i]);
 				break;
 		}
 	}
@@ -1032,8 +1087,7 @@
 MR_write_out_ho_call_site_nodes(FILE *fp, MR_CallSiteDynList *dynlist)
 {
 	while (dynlist != NULL) {
-		MR_write_out_call_site_dynamic(fp,
-			dynlist->MR_csdlist_call_site);
+        MR_write_out_call_site_dynamic(fp, dynlist->MR_csdlist_call_site);
 		dynlist = dynlist->MR_csdlist_next;
 	}
 }
@@ -1046,8 +1100,7 @@
 	if (csd == NULL) {
 		csd_id = 0;
 	} else {
-		(void) MR_hash_table_insert(MR_call_site_dynamic_table, csd,
-			&csd_id, NULL, MR_FALSE);
+        (void) MR_insert_call_site_dynamic(csd, &csd_id, NULL, MR_FALSE);
 	}
 
 	MR_write_ptr(fp, kind_csd, csd_id);
@@ -1080,10 +1133,8 @@
 	/* convert from a MR_CallSite_Kind to an MR_Profiling_Encoding_Token */
 	byte = (int) kind +
 		((int) MR_deep_token_normal_call - (int) MR_normal_call);
-	if (byte < MR_deep_token_normal_call || byte > MR_deep_token_callback)
-	{
-		MR_fatal_error("MR_write_kind: bad kind %d %d\n",
-			(int) kind, byte);
+    if (byte < MR_deep_token_normal_call || byte > MR_deep_token_callback) {
+        MR_fatal_error("MR_write_kind: bad kind %d %d\n", (int) kind, byte);
 	}
 
 	MR_write_byte(fp, byte);
@@ -1158,7 +1209,8 @@
 static void
 MR_write_string(FILE *fp, const char *ptr)
 {
-	int	i, len;
+    int i;
+    int len;
 
 #ifdef	MR_DEEP_PROFILING_DETAIL_DEBUG
 	if (debug_fp != NULL) {
@@ -1191,6 +1243,7 @@
 MR_create_hash_table(int size)
 {
 	MR_ProfilingHashTable *ptr;
+
 	ptr = MR_NEW(MR_ProfilingHashTable);
 	ptr->length = size;
 	ptr->last_id = 0;
@@ -1199,10 +1252,91 @@
 	return ptr;
 }
 
+/****************************************************************************/
+/*
+** Type safe interfaces to the generic hash table routines.
+**
+** We declare those generic routines here to ensure that any calls to them
+** from above this point get error messages from mgnuc.
+*/
+
+static  MR_bool                 MR_hash_table_insert_INTERNAL(
+                                    MR_ProfilingHashTable *table,
+                                    const void *ptr, int *id,
+                                    MR_bool *already_written,
+                                    MR_bool init_written);
+static  void                    MR_hash_table_flag_written_INTERNAL(
+                                    MR_ProfilingHashTable *table,
+                                    const void *ptr);
+static  int                     MR_hash_table_check_all_written_INTERNAL(
+                                    FILE *fp, const char *type,
+                                    MR_ProfilingHashTable *table,
+                                    void write_func(FILE *fp, const void *));
+
+static MR_bool
+MR_insert_proc_layout(const MR_Proc_Layout *pl, int *id,
+    MR_bool *already_written, MR_bool init_written)
+{
+    return MR_hash_table_insert_INTERNAL(MR_proc_layout_table,
+        (const void *) pl, id, already_written, init_written);
+}
+
+static MR_bool
+MR_insert_proc_dynamic(const MR_ProcDynamic *pd, int *id,
+    MR_bool *already_written, MR_bool init_written)
+{
+    return MR_hash_table_insert_INTERNAL(MR_proc_dynamic_table,
+        (const void *) pd, id, already_written, init_written);
+}
+
+static MR_bool
+MR_insert_call_site_static(const MR_CallSiteStatic *css, int *id,
+    MR_bool *already_written, MR_bool init_written)
+{
+    return MR_hash_table_insert_INTERNAL(MR_call_site_dynamic_table,
+        (const void *) css, id, already_written, init_written);
+}
+
+static MR_bool
+MR_insert_call_site_dynamic(const MR_CallSiteDynamic *csd, int *id,
+    MR_bool *already_written, MR_bool init_written)
+{
+    return MR_hash_table_insert_INTERNAL(MR_call_site_dynamic_table,
+        (const void *) csd, id, already_written, init_written);
+}
+
+static void
+MR_flag_written_proc_layout(const MR_Proc_Layout *pl)
+{
+    MR_hash_table_flag_written_INTERNAL(MR_proc_layout_table,
+        (const void *) pl);
+}
+
+static void
+MR_flag_written_proc_dynamic(const MR_ProcDynamic *pd)
+{
+    MR_hash_table_flag_written_INTERNAL(MR_proc_dynamic_table,
+        (const void *) pd);
+}
+
+static void
+MR_flag_written_call_site_static(const MR_CallSiteStatic *css)
+{
+    MR_hash_table_flag_written_INTERNAL(MR_call_site_static_table,
+        (const void *) css);
+}
+
+static void
+MR_flag_written_call_site_dynamic(const MR_CallSiteDynamic *csd)
+{
+    MR_hash_table_flag_written_INTERNAL(MR_call_site_dynamic_table,
+        (const void *) csd);
+}
+
 #define	MR_hash_ptr(ptr, table)	(((unsigned int) (ptr) >> 2) % (table)->length)
 
 static MR_bool
-MR_hash_table_insert(MR_ProfilingHashTable *table, const void *ptr,
+MR_hash_table_insert_INTERNAL(MR_ProfilingHashTable *table, const void *ptr,
 	int *id, MR_bool *already_written, MR_bool init_written)
 {
 	int			hash;
@@ -1241,7 +1375,8 @@
 }
 
 static void
-MR_hash_table_flag_written(MR_ProfilingHashTable *table, const void *ptr)
+MR_hash_table_flag_written_INTERNAL(MR_ProfilingHashTable *table,
+    const void *ptr)
 {
 	int			hash;
 	MR_ProfilingHashNode	*node;
@@ -1263,6 +1398,134 @@
 	MR_fatal_error("MR_hash_table_flag_written: did not find node");
 }
 
+static void
+MR_write_out_profiling_tree_check_unwritten(FILE *check_fp)
+{
+    int                     unwritten_csd;
+    int                     unwritten_css;
+    int                     unwritten_pd;
+    int                     unwritten_ps;
+    int                     any_unwritten;
+    int                     iteration;
+
+    unwritten_ps = MR_hash_table_check_all_written_INTERNAL(check_fp,
+        "ProcLayout", MR_proc_layout_table,
+        MR_unwritten_pl_handler);
+    unwritten_pd = MR_hash_table_check_all_written_INTERNAL(check_fp,
+        "ProcDynamic", MR_proc_dynamic_table,
+        MR_unwritten_pd_handler);
+    unwritten_css = MR_hash_table_check_all_written_INTERNAL(check_fp,
+        "CallSiteStatic", MR_call_site_static_table,
+        MR_unwritten_css_handler);
+    unwritten_csd = MR_hash_table_check_all_written_INTERNAL(check_fp,
+        "CallSiteDynamic", MR_call_site_dynamic_table,
+        MR_unwritten_csd_handler);
+    any_unwritten = unwritten_ps + unwritten_pd +
+        unwritten_css + unwritten_csd;
+
+    if (unwritten_ps > 0 && check_fp != NULL) {
+        fprintf(check_fp, "%d unwritten proc statics\n",
+            unwritten_ps);
+    }
+
+    if (unwritten_pd > 0 && check_fp != NULL) {
+        fprintf(check_fp, "%d unwritten proc dynamics\n",
+            unwritten_pd);
+    }
+
+    if (unwritten_css > 0 && check_fp != NULL) {
+        fprintf(check_fp, "%d unwritten call site statics\n",
+            unwritten_css);
+    }
+
+    if (unwritten_csd > 0 && check_fp != NULL) {
+        fprintf(check_fp, "%d unwritten call site dynamics\n",
+            unwritten_csd);
+    }
+
+    if (any_unwritten > 0) {
+        MR_fatal_error("UNWRITTEN nodes: Deep.data file corrupted\n");
+    }
+}
+
+static void
+MR_unwritten_css_handler(FILE *fp, const void *css)
+{
+    fprintf(stderr, "UNWRITTEN call site static %p\n", css);
+}
+
+static void
+MR_unwritten_csd_handler(FILE *fp, const void *csd)
+{
+    fprintf(stderr, "UNWRITTEN call site dynamic %p\n", csd);
+}
+
+static void
+MR_unwritten_pl_handler(FILE *fp, const void *pl)
+{
+    const MR_Proc_Layout    *proc_layout;
+    const MR_Proc_Id        *procid;
+
+    proc_layout = (const MR_Proc_Layout *) pl;
+
+    if (! MR_PROC_LAYOUT_HAS_PROC_ID(proc_layout)) {
+        MR_fatal_error("MR_write_out_proc_layout_from_void: no proc_id\n");
+    }
+
+    procid = &proc_layout->MR_sle_proc_id;
+    if (MR_PROC_ID_IS_UCI(*procid)) {
+        fprintf(stderr, "uci %s/%s/%s/%s/%d/%d\n",
+            procid->MR_proc_uci.MR_uci_type_name,
+            procid->MR_proc_uci.MR_uci_type_module,
+            procid->MR_proc_uci.MR_uci_def_module,
+            procid->MR_proc_uci.MR_uci_pred_name,
+            procid->MR_proc_uci.MR_uci_type_arity,
+            procid->MR_proc_uci.MR_uci_mode);
+    } else {
+        fprintf(stderr, "user %d/%s/%s/%s/%d/%d\n",
+            procid->MR_proc_user.MR_user_pred_or_func,
+            procid->MR_proc_user.MR_user_decl_module,
+            procid->MR_proc_user.MR_user_def_module,
+            procid->MR_proc_user.MR_user_name,
+            procid->MR_proc_user.MR_user_arity,
+            procid->MR_proc_user.MR_user_mode);
+    }
+
+    fprintf(stderr, "UNWRITTEN proc layout %p\n", pl);
+}
+
+static void
+MR_unwritten_pd_handler(FILE *fp, const void *pd)
+{
+    fprintf(stderr, "UNWRITTEN proc dynamic %p\n", pd);
+}
+
+static int
+MR_hash_table_check_all_written_INTERNAL(FILE *fp, const char *type,
+    MR_ProfilingHashTable *table, void write_func(FILE *, const void *))
+{
+    int                     i;
+    int                     errors;
+    MR_ProfilingHashNode    *node;
+
+    errors = 0;
+    for (i = 0; i < table->length ; i++) {
+        for (node = table->nodes[i]; node != NULL; node = node->next) {
+            if (! node->written) {
+                errors++;
+                if (fp != NULL) {
+                    fprintf(fp, "unwritten %s %d at %p\n",
+                        type, node->id, node->item);
+                    fflush(fp);
+                    (*write_func)(fp, node->item);
+                }
+            }
+        }
+    }
+
+    return errors;
+}
+
 /*----------------------------------------------------------------------------*/
 
 void
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/general/string_format
cvs diff: Diffing tests/general/structure_reuse
cvs diff: Diffing tests/grade_subdirs
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/mmc_make
cvs diff: Diffing tests/mmc_make/lib
cvs diff: Diffing tests/recompilation
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing util
cvs diff: Diffing vim
cvs diff: Diffing vim/after
cvs diff: Diffing vim/ftplugin
cvs diff: Diffing vim/syntax
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list