[m-rev.] Post-commit review: Implement several things for RBMM
Quan Phan
quan.phan at cs.kuleuven.be
Fri Nov 23 04:05:41 AEDT 2007
Sorry for the last email to developer list, it should go here.
Quan.
On Thu, Nov 22, 2007 at 05:59:51PM +0100, Quan Phan wrote:
Hi,
I am going to commit this change because it is only affected RBMM stuff.
This is actually the change I posted on Oct. 16 (but did not commit),
plus some more minor changes.
Regards,
Quan.
Estimated hours taken: 10.
Branch: main
Implement several things for region-based memory management:
Improve debugging messages.
Collect more profiling information.
Fix some bugs.
Change more pointer arithmetics to structs.
Make the implementation of the RBMM runtime support for if-then-else,
disjunction, and commit more consistent
compiler/ite_gen.m:
Remove a redundant if-then-else.
compiler/options.m:
Keep it consistent with changes in mercury_region.h.
runtime/mercury_region.c:
runtime/mercury_region.h:
Implement all the above changes.
cvs diff: Diffing analysis
cvs diff: Diffing bench
cvs diff: Diffing bench/progs
cvs diff: Diffing bench/progs/compress
cvs diff: Diffing bench/progs/icfp2000
cvs diff: Diffing bench/progs/icfp2001
cvs diff: Diffing bench/progs/nuc
cvs diff: Diffing bench/progs/ray
cvs diff: Diffing bench/progs/tree234
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/libatomic_ops-1.2
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/doc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/gcc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/hpc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/ibmc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/icc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/msftc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/src/atomic_ops/sysdeps/sunc
cvs diff: Diffing boehm_gc/libatomic_ops-1.2/tests
cvs diff: Diffing boehm_gc/tests
cvs diff: Diffing boehm_gc/windows-untested
cvs diff: Diffing boehm_gc/windows-untested/vc60
cvs diff: Diffing boehm_gc/windows-untested/vc70
cvs diff: Diffing boehm_gc/windows-untested/vc71
cvs diff: Diffing browser
cvs diff: Diffing browser/test
cvs diff: Diffing bytecode
cvs diff: Diffing bytecode/test
cvs diff: Diffing compiler
Index: compiler/ite_gen.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/ite_gen.m,v
retrieving revision 1.103
diff -u -r1.103 ite_gen.m
--- compiler/ite_gen.m 9 Oct 2007 07:59:46 -0000 1.103
+++ compiler/ite_gen.m 22 Nov 2007 16:36:05 -0000
@@ -602,12 +602,8 @@
CondRemovedRegionVars),
SnapshotRegionVars0 = set.intersect(LiveRegionVars,
CondAllocRegionVars),
- ( set.empty(UnprotectedRemovedAtStartOfElse) ->
- SnapshotRegionVars = SnapshotRegionVars0
- ;
- SnapshotRegionVars = set.difference(SnapshotRegionVars0,
- UnprotectedRemovedAtStartOfElse)
- ),
+ SnapshotRegionVars = set.difference(SnapshotRegionVars0,
+ UnprotectedRemovedAtStartOfElse),
ProtectRegionVarList = set.to_sorted_list(ProtectRegionVars),
SnapshotRegionVarList = set.to_sorted_list(SnapshotRegionVars),
Index: compiler/options.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.602
diff -u -r1.602 options.m
--- compiler/options.m 12 Nov 2007 03:52:43 -0000 1.602
+++ compiler/options.m 22 Nov 2007 16:36:07 -0000
@@ -1210,13 +1210,18 @@
use_minimal_model_stack_copy_pneg - bool(no),
use_minimal_model_stack_copy_cut - bool(no),
disable_trail_ops - bool(no),
- % The values here must be consistent with those in mercury_region.h.
+ % The size_* values below *must* be consistent with the corresponding
+ % values or data structures in mercury_region.h.
size_region_ite_fixed - int(4),
- size_region_disj_fixed - int(4),
+ size_region_disj_fixed - int(3),
size_region_commit_fixed - int(4),
size_region_ite_protect - int(1),
size_region_ite_snapshot - int(4),
size_region_disj_protect - int(0),
+ % size_region_disj_protect is no longer
+ % used. It should be removed when the
+ % runtime support for RBMM is more
+ % stable.
size_region_disj_snapshot - int(4),
size_region_commit_entry - int(1),
solver_type_auto_init - bool(no)
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing debian/patches
cvs diff: Diffing deep
cvs diff: Diffing deep_profiler
cvs diff: Diffing deep_profiler/notes
cvs diff: Diffing detail
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/base64
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/concurrency/samples
cvs diff: Diffing extras/concurrency/samples/midi
cvs diff: Diffing extras/concurrency/tests
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/exceptions
cvs diff: Diffing extras/fixed
cvs diff: Diffing extras/gator
cvs diff: Diffing extras/gator/generations
cvs diff: Diffing extras/gator/generations/1
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/easyx
cvs diff: Diffing extras/graphics/easyx/samples
cvs diff: Diffing extras/graphics/mercury_allegro
cvs diff: Diffing extras/graphics/mercury_allegro/examples
cvs diff: Diffing extras/graphics/mercury_allegro/samples
cvs diff: Diffing extras/graphics/mercury_allegro/samples/demo
cvs diff: Diffing extras/graphics/mercury_allegro/samples/mandel
cvs diff: Diffing extras/graphics/mercury_allegro/samples/pendulum2
cvs diff: Diffing extras/graphics/mercury_allegro/samples/speed
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/lazy_evaluation/examples
cvs diff: Diffing extras/lex
cvs diff: Diffing extras/lex/samples
cvs diff: Diffing extras/lex/tests
cvs diff: Diffing extras/log4m
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/mopenssl
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/net
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/opium_m
cvs diff: Diffing extras/opium_m/non-regression-tests
cvs diff: Diffing extras/opium_m/scripts
cvs diff: Diffing extras/opium_m/source
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/posix/samples
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/solver_types
cvs diff: Diffing extras/solver_types/library
cvs diff: Diffing extras/stream
cvs diff: Diffing extras/stream/tests
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/windows_installer_generator
cvs diff: Diffing extras/windows_installer_generator/sample
cvs diff: Diffing extras/windows_installer_generator/sample/images
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/library
cvs diff: Diffing java/runtime
cvs diff: Diffing library
cvs diff: Diffing lp_solve
cvs diff: Diffing lp_solve/lp_examples
cvs diff: Diffing mdbcomp
cvs diff: Diffing profiler
cvs diff: Diffing quickcheck
cvs diff: Diffing quickcheck/tutes
cvs diff: Diffing readline
cvs diff: Diffing readline/doc
cvs diff: Diffing readline/examples
cvs diff: Diffing readline/shlib
cvs diff: Diffing readline/support
cvs diff: Diffing robdd
cvs diff: Diffing runtime
Index: runtime/mercury_region.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_region.c,v
retrieving revision 1.3
diff -u -r1.3 mercury_region.c
--- runtime/mercury_region.c 15 Oct 2007 08:14:56 -0000 1.3
+++ runtime/mercury_region.c 22 Nov 2007 16:36:09 -0000
@@ -35,12 +35,14 @@
MR_RegionProfUnit MR_rbmmp_pages_used = {0, 0, 0};
unsigned int MR_rbmmp_pages_requested = 0;
unsigned int MR_rbmmp_biggest_region_size = 0;
-MR_RegionProfUnit MR_rbmmp_regions_saved_at_commit = {0, 0, 0};
-unsigned int MR_rbmmp_regions_protected_at_ite;
-unsigned int MR_rbmmp_snapshots_saved_at_ite;
+unsigned int MR_rbmmp_regions_saved_at_commit = 0;
+unsigned int MR_rbmmp_regions_protected_at_ite = 0;
+unsigned int MR_rbmmp_snapshots_saved_at_ite = 0;
unsigned int MR_rbmmp_regions_protected_at_disj;
-unsigned int MR_rbmmp_snapshots_saved_at_disj;
+unsigned int MR_rbmmp_snapshots_saved_at_disj = 0;
double MR_rbmmp_page_utilized;
+unsigned int MR_rbmmp_words_snapshot_instant_reclaimed = 0;
+unsigned int MR_rbmmp_pages_snapshot_instant_reclaimed = 0;
#endif
@@ -68,6 +70,9 @@
MR_RegionProfUnit *profiling_unit);
#endif
+static void MR_region_get_new_pages_and_new_words(
+ MR_RegionSnapshot *snapshot, int *new_pages,
+ int *new_words);
/*---------------------------------------------------------------------------*/
/* Page operations. */
@@ -162,9 +167,7 @@
region->MR_region_previous_region = NULL;
MR_live_region_list = region;
-#if defined(MR_RBMM_DEBUG)
MR_region_debug_create_region(region);
-#endif
#if defined(MR_RBMM_PROFILING)
MR_region_update_profiling_unit(&MR_rbmmp_regions_used, 1);
@@ -241,8 +244,6 @@
void
MR_region_destroy_region(MR_Region *region)
{
- MR_region_debug_destroy_region(region);
-
if (region->MR_region_commit_frame != NULL) {
MR_region_nullify_entries_in_commit_stack(region);
}
@@ -281,12 +282,10 @@
MR_region_debug_try_remove_region(region);
if ( !MR_region_is_disj_protected(region) ) {
MR_region_destroy_region(region);
+ MR_region_debug_destroy_region(region);
} else {
region->MR_region_logical_removed = 1;
-
-#if defined(MR_RBMM_DEBUG)
- MR_region_logically_remove_region_msg(region);
-#endif
+ MR_region_debug_logically_remove_region(region);
}
}
@@ -305,12 +304,10 @@
if ( !MR_region_is_disj_protected(region) ) {
MR_region_nullify_in_ite_frame(region);
MR_region_destroy_region(region);
+ MR_region_debug_destroy_region(region);
} else {
region->MR_region_logical_removed = 1;
-
-#if defined(MR_RBMM_DEBUG)
- MR_region_logically_remove_region_msg(region);
-#endif
+ MR_region_debug_logically_remove_region(region);
}
}
@@ -327,12 +324,18 @@
region->MR_region_logical_removed = 1;
/*
- ** This logical removal happens in a commit operation. Therefore we
- ** mark the region so that it will be destroyed at the commit point.
+ ** This logical removal happens in a commit operation. If the region
+ ** is *new* since the start of the commit we mark the region so that it
+ ** will be destroyed at the commit point.
*/
- if (MR_region_commit_sp != NULL) {
+ if (MR_region_commit_sp != NULL &&
+ MR_region_commit_sp->MR_rcff_saved_sequence_number <=
+ region->MR_region_sequence_number) {
region->MR_region_destroy_at_commit = 1;
}
+ /*if (MR_region_commit_sp != NULL) {
+ region->MR_region_destroy_at_commit = 1;
+ }*/
#if defined(MR_RBMM_DEBUG)
MR_region_logically_remove_region_msg(region);
@@ -373,7 +376,7 @@
region->MR_region_available_space = MR_REGION_PAGE_SPACE_SIZE;
}
-/* Destroy any marked regions allocated before scope entry. */
+/* Destroy any marked regions allocated before the commit. */
void
MR_commit_success_destroy_marked_saved_regions(MR_Word num_saved_regions,
MR_RegionCommitSave *first_commit_save)
@@ -388,28 +391,20 @@
if (region != NULL) {
/*
** The region is saved here and has not been destroyed.
- ** XXX If we save only regions that are live at entry and not live
- ** at exit, at commit it should be the case that a logical removal
- ** has happened to the region, i.e., destroy_at_commit = 1. So just
- ** need to destroy it at commit. The check and the else below are
- ** redundant.
+ ** XXX Because we save only regions that are live at entry, not
+ ** live at exit, and not protected at entry, at the commit point it
+ ** must be the case that a logical removal has happened to the
+ ** region, So just need to destroy it at commit.
*/
- if (region->MR_region_destroy_at_commit) {
- /*
- ** Logical removal happens to the region in the commit
- ** context. So destroy it at commit.
- */
- MR_region_destroy_region(region);
- } else {
- MR_fatal_error(
- "MR_commit_success_destroy_marked_saved_regions: "
- "need to rethink.");
- }
+ MR_region_destroy_region(region);
}
}
}
-/* Destroy any marked regions allocated since scope entry. */
+/*
+** Destroy any marked regions allocated since scope entry, i.e., *new* to
+** the commit.
+*/
void
MR_commit_success_destroy_marked_new_regions(MR_Word saved_region_seq_number)
{
@@ -417,7 +412,7 @@
region = MR_live_region_list;
while (region != NULL &&
- region->MR_region_sequence_number > saved_region_seq_number)
+ region->MR_region_sequence_number >= saved_region_seq_number)
{
if (region->MR_region_destroy_at_commit) {
MR_region_destroy_region(region);
@@ -434,23 +429,13 @@
int
MR_region_is_disj_protected(MR_Region *region)
{
- MR_RegionDisjFixedFrame *disj_frame;
-
- disj_frame = MR_region_disj_sp;
- while (disj_frame != NULL)
- {
- if (disj_frame->MR_rdff_disj_prot_seq_number !=
- MR_REGION_DISJ_FRAME_DUMMY_SEQ_NUMBER &&
- disj_frame->MR_rdff_disj_prot_seq_number <
+ if (MR_region_disj_sp != NULL &&
+ MR_region_disj_sp->MR_rdff_saved_sequence_number >
region->MR_region_sequence_number) {
- return MR_TRUE;
- }
- disj_frame = disj_frame->MR_rdff_previous_disj_frame;
- }
+ return MR_TRUE;
+ }
return MR_FALSE;
}
-
-
/*---------------------------------------------------------------------------*/
/* Debugging messages for RBMM. */
@@ -473,8 +458,8 @@
void
MR_region_create_region_msg(MR_Region *region)
{
- printf("Create region #%d:\n", region->MR_region_sequence_number);
- printf("\tHandle: %d\n", region);
+ printf("Create region #%d (%d).\n", region->MR_region_sequence_number,
+ region);
}
void
@@ -487,28 +472,26 @@
void
MR_region_destroy_region_msg(MR_Region *region)
{
- printf("Destroy region ");
- MR_region_region_struct_removal_info_msg(region);
+ printf("Destroy region #%d.\n", region->MR_region_sequence_number);
}
void
MR_region_logically_remove_region_msg(MR_Region *region)
{
- printf("Logically remove region ");
- MR_region_region_struct_removal_info_msg(region);
+ printf("Logically removed region #%d.\n",
+ region->MR_region_sequence_number);
}
void
MR_region_region_struct_removal_info_msg(MR_Region *region)
{
- printf("#%d\n", region->MR_region_sequence_number);
- printf("\tHandle: %d\n", region);
+ printf("#%d (%d)\n", region->MR_region_sequence_number, region);
printf("\tLogically removed: %d\n", region->MR_region_logical_removed);
- printf("\tProtected by ite frame #%d: %d\n",
+ printf("\tIte-protected by #%d: %d\n",
MR_region_get_frame_number((MR_Word *)region->MR_region_ite_protected),
region->MR_region_ite_protected);
if ( MR_region_is_disj_protected(region) ) {
- printf("\tProtected by a disj frame.\n");
+ printf("\tDisj-protected.\n");
} else {
printf("\tNot disj-protected.\n");
}
@@ -522,16 +505,16 @@
void
MR_region_push_ite_frame_msg(MR_RegionIteFixedFrame *ite_frame)
{
- int frame_number;
+ int frame_number;
frame_number = MR_region_get_frame_number( (MR_Word *) ite_frame);
printf("Push ite frame #%d: %d\n", frame_number, ite_frame);
- printf("\tPrevious frame at push #%d: %d\n",
+ printf("\tPrevious #%d: %d\n",
MR_region_get_frame_number(
(MR_Word *) (ite_frame->MR_riff_previous_ite_frame)),
ite_frame->MR_riff_previous_ite_frame);
- printf("\tSaved most recent region at push: %d\n",
- ite_frame->MR_riff_saved_region_list);
+ printf("\tSaved sequence number: %d\n",
+ ite_frame->MR_riff_saved_sequence_number);
}
void
@@ -539,11 +522,12 @@
{
printf("Ite frame #%d: %d\n",
MR_region_get_frame_number( (MR_Word *) ite_frame), ite_frame);
- printf("\tPrevious frame #%d: %d\n",
+ printf("\tPrevious #%d: %d\n",
MR_region_get_frame_number(
(MR_Word *) (ite_frame->MR_riff_previous_ite_frame)),
ite_frame->MR_riff_previous_ite_frame);
- printf("\tSaved most recent: %d\n", ite_frame->MR_riff_saved_region_list);
+ printf("\tSaved sequence number: %d\n",
+ ite_frame->MR_riff_saved_sequence_number);
MR_region_ite_frame_protected_regions_msg(ite_frame);
MR_region_ite_frame_snapshots_msg(ite_frame);
}
@@ -568,7 +552,7 @@
(MR_Word *) ite_frame + MR_REGION_ITE_FRAME_FIXED_SIZE);
for (i = 0; i < ite_frame->MR_riff_num_prot_regions; i++, ite_prot++) {
printf("\tAt slot: %d, ite-protect region: %d\n",
- ite_prot, ite_prot->MR_ite_prot_region);
+ ite_prot, ite_prot->MR_ite_prot_region->MR_region_sequence_number);
}
}
@@ -589,8 +573,8 @@
snapshot = (MR_RegionSnapshot *) ((MR_Word *) ite_frame +
MR_REGION_ITE_FRAME_FIXED_SIZE + protection_size);
for (i = 0; i < ite_frame->MR_riff_num_snapshots; i++, snapshot++) {
- printf("\tAt slot: %d, snapshot of region: %d\n", snapshot,
- snapshot->MR_snapshot_region);
+ printf("\tAt slot: %d, snapshot of region: #%d\n", snapshot,
+ snapshot->MR_snapshot_region->MR_region_sequence_number);
}
}
@@ -599,12 +583,12 @@
{
printf("Push disj frame #%d: %d\n",
MR_region_get_frame_number((MR_Word *) disj_frame), disj_frame);
- printf("\tPrevious frame at push #%d: %d\n",
+ printf("\tPrevious #%d: %d\n",
MR_region_get_frame_number(
(MR_Word *) (disj_frame->MR_rdff_previous_disj_frame)),
disj_frame->MR_rdff_previous_disj_frame);
- printf("\tSaved most recent region at push: %d\n",
- disj_frame->MR_rdff_saved_region_list);
+ printf("\tSaved sequence number: %d\n",
+ disj_frame->MR_rdff_saved_sequence_number);
}
void
@@ -612,12 +596,12 @@
{
printf("Disj frame #%d: %d\n",
MR_region_get_frame_number((MR_Word *) disj_frame), disj_frame);
- printf("\tPrevious frame #%d: %d\n",
+ printf("\tPrevious #%d: %d\n",
MR_region_get_frame_number(
(MR_Word *) disj_frame->MR_rdff_previous_disj_frame),
disj_frame->MR_rdff_previous_disj_frame);
- printf("\tSaved most recent region: %d\n",
- disj_frame->MR_rdff_saved_region_list);
+ printf("\tSaved sequence number: %d\n",
+ disj_frame->MR_rdff_saved_sequence_number);
}
void
@@ -646,13 +630,13 @@
printf("Push commit frame #%d: %d\n",
MR_region_get_frame_number((MR_Word *) commit_frame), commit_frame);
- printf("\tPrevious frame at push #%d: %d\n",
+ printf("\tPrevious #%d: %d\n",
MR_region_get_frame_number(
(MR_Word *) commit_frame->MR_rcff_previous_commit_frame),
commit_frame->MR_rcff_previous_commit_frame);
- printf("\tSequence number at push: %d\n",
+ printf("\tSequence number: %d\n",
commit_frame->MR_rcff_saved_sequence_number);
- printf("\tDisj frame at push #%d: %d\n",
+ printf("\tDisj frame #%d: %d\n",
MR_region_get_frame_number(
(MR_Word *) (commit_frame->MR_rcff_saved_disj_sp)),
commit_frame->MR_rcff_saved_disj_sp);
@@ -670,9 +654,9 @@
MR_region_get_frame_number(
(MR_Word *) commit_frame->MR_rcff_previous_commit_frame),
commit_frame->MR_rcff_previous_commit_frame);
- printf("\tSequence number at push: %d\n",
+ printf("\tSequence number: %d\n",
commit_frame->MR_rcff_saved_sequence_number);
- printf("\tDisj frame at push #%d: %d\n",
+ printf("\tDisj frame #%d: %d\n",
MR_region_get_frame_number(
(MR_Word *) (commit_frame->MR_rcff_saved_disj_sp)),
commit_frame->MR_rcff_saved_disj_sp);
@@ -721,6 +705,97 @@
}
+void
+MR_region_start_msg(const char *name)
+{
+ printf("Start %s:\n", name);
+}
+
+void
+MR_region_end_msg(const char *name)
+{
+ printf("End %s.\n", name);
+}
+
+void
+MR_region_fill_ite_protect_msg(MR_RegionIteProtect *ite_prot,
+ MR_Region *region)
+{
+ if (ite_prot == NULL) {
+ printf("\tNot protect region #%d.\n",
+ region->MR_region_sequence_number);
+ } else {
+ printf("\tAt slot: %d, protect region #%d.\n", ite_prot,
+ region->MR_region_sequence_number);
+ }
+}
+
+void
+MR_region_fill_ite_snapshot_removed_msg(MR_RegionSnapshot *snapshot,
+ MR_Region *region)
+{
+ if (snapshot == NULL) {
+ printf("\tNot take snapshot of region #%d.\n",
+ region->MR_region_sequence_number);
+ } else {
+ printf("\tAt slot: %d, save snapshot of region #%d.\n", snapshot,
+ region->MR_region_sequence_number);
+ }
+}
+
+void
+MR_region_fill_ite_snapshot_not_removed_msg(MR_RegionSnapshot *snapshot,
+ MR_Region *region)
+{
+ printf("\tAt slot: %d, save snapshot of region #%d.\n", snapshot,
+ region->MR_region_sequence_number);
+}
+
+void
+MR_region_fill_disj_snapshot_msg(MR_RegionSnapshot *snapshot,
+ MR_Region *region)
+{
+ printf("\tAt slot: %d, save snapshot of region #%d.\n", snapshot,
+ region->MR_region_sequence_number);
+}
+
+void
+MR_region_fill_commit_msg(MR_RegionCommitSave *commit_save,
+ MR_Region *region)
+{
+ if (commit_save == NULL) {
+ printf("\tNot save region #%d.\n", region->MR_region_sequence_number);
+ } else {
+ printf("\tAt slot: %d, save region #%d.\n", commit_save,
+ region->MR_region_sequence_number);
+ }
+}
+
+void
+MR_region_ite_unprotect_msg(MR_Region *region)
+{
+ MR_RegionIteFixedFrame *old_ite_frame;
+ MR_RegionIteFixedFrame *new_ite_frame;
+
+ old_ite_frame = region->MR_region_ite_protected;
+ new_ite_frame = MR_region_ite_sp->MR_riff_previous_ite_frame;
+ printf("Ite protected by #%d (%d), now by #%d (%d).\n",
+ MR_region_get_frame_number((MR_Word *) old_ite_frame), old_ite_frame,
+ MR_region_get_frame_number((MR_Word *) new_ite_frame), new_ite_frame);
+}
+
+void
+MR_region_restore_from_snapshot_msg(MR_RegionSnapshot *snapshot)
+{
+ int new_words;
+ int new_pages;
+
+ MR_region_get_new_pages_and_new_words(snapshot, &new_pages, &new_words);
+ printf("Restore region #%d: reclaim %d pages, %d words.\n",
+ snapshot->MR_snapshot_region->MR_region_sequence_number,
+ new_pages, new_words);
+}
+
#endif /* End of MR_RBMM_DEBUG. */
/*---------------------------------------------------------------------------*/
@@ -765,28 +840,24 @@
void
MR_region_profile_restore_from_snapshot(MR_RegionSnapshot *snapshot)
{
- MR_Region *restoring_region;
- MR_RegionPage *first_new_page;
int new_words;
int new_pages;
+ MR_Region *restoring_region;
+ MR_region_get_new_pages_and_new_words(snapshot, &new_pages, &new_words);
+ MR_region_update_profiling_unit(&MR_rbmmp_pages_used, -new_pages);
restoring_region = snapshot->MR_snapshot_region;
- first_new_page = snapshot->MR_snapshot_saved_last_page->MR_regionpage_next;
-
- if (first_new_page != NULL) {
- new_pages = MR_region_get_number_of_pages(first_new_page,
- restoring_region->MR_region_last_page);
- MR_region_update_profiling_unit(&MR_rbmmp_pages_used, -new_pages);
- new_words = (new_pages * MR_REGION_PAGE_SPACE_SIZE -
- restoring_region->MR_region_available_space +
- snapshot->MR_snapshot_saved_available_space);
- } else {
- new_words = snapshot->MR_snapshot_saved_available_space -
- restoring_region->MR_region_available_space;
- }
((MR_RegionPage *) restoring_region)->MR_regionpage_allocated_size
-= new_words;
MR_region_update_profiling_unit(&MR_rbmmp_words_used, -new_words);
+ MR_rbmmp_pages_snapshot_instant_reclaimed += new_pages;
+ MR_rbmmp_words_snapshot_instant_reclaimed += new_words;
+}
+
+void
+MR_region_profile_increase_counter(unsigned int *counter)
+{
+ *counter += 1;
}
int
@@ -810,7 +881,7 @@
MR_region_print_profiling_unit(const char *str,
MR_RegionProfUnit *profiling_unit)
{
- printf(str); /* XXX This is dangerous. */
+ printf("%s", str);
printf("\n");
printf("\tTotal: %d.\n", profiling_unit->MR_rbmmpu_total);
printf("\tMaximum: %d.\n", profiling_unit->MR_rbmmpu_max);
@@ -820,11 +891,25 @@
void
MR_region_print_profiling_info(void)
{
+ printf("\n---------- Profiling information ----------\n");
MR_region_print_profiling_unit("Regions:", &MR_rbmmp_regions_used);
printf("Biggest region size: %d.\n", MR_rbmmp_biggest_region_size);
MR_region_print_profiling_unit("Words:", &MR_rbmmp_words_used);
MR_region_print_profiling_unit("Pages used:", &MR_rbmmp_pages_used);
printf("Pages requested: %d.\n", MR_rbmmp_pages_requested);
+ printf("Pages utilized: %lf.\n",
+ MR_rbmmp_pages_used.MR_rbmmpu_total / (double)MR_rbmmp_pages_requested);
+ printf("Regions protected at ite frames: %d.\n",
+ MR_rbmmp_regions_protected_at_ite);
+ printf("Regions saved at commit frames: %d.\n",
+ MR_rbmmp_regions_saved_at_commit);
+ printf("Snapshots at ite frames: %d.\n", MR_rbmmp_snapshots_saved_at_ite);
+ printf("Snapshots at disj frames: %d.\n",
+ MR_rbmmp_snapshots_saved_at_disj);
+ printf("Words instant reclaimed thanks to snapshot: %d.\n",
+ MR_rbmmp_words_snapshot_instant_reclaimed);
+ printf("Pages instant reclaimed thanks to snapshot: %d.\n",
+ MR_rbmmp_pages_snapshot_instant_reclaimed);
}
#else /* Not define MR_RBMM_PROFILING. */
@@ -847,6 +932,12 @@
/* do nothing */
}
+void
+MR_region_profile_increase_counter(unsigned int *counter)
+{
+ /* do nothing */
+}
+
int
MR_region_get_number_of_pages(MR_RegionPage *fp, MR_RegionPage *tp)
{
@@ -860,4 +951,28 @@
#endif /* End of Not define MR_RBMM_PROFILING. */
+static void
+MR_region_get_new_pages_and_new_words(MR_RegionSnapshot *snapshot,
+ int *new_pages, int *new_words)
+{
+ MR_Region *restoring_region;
+ MR_RegionPage *first_new_page;
+
+ restoring_region = snapshot->MR_snapshot_region;
+ first_new_page = snapshot->MR_snapshot_saved_last_page->MR_regionpage_next;
+
+ if (first_new_page != NULL) {
+ *new_pages = MR_region_get_number_of_pages(first_new_page,
+ restoring_region->MR_region_last_page);
+ *new_words = (*new_pages * MR_REGION_PAGE_SPACE_SIZE -
+ restoring_region->MR_region_available_space +
+ snapshot->MR_snapshot_saved_available_space);
+ } else {
+ *new_pages = 0;
+ *new_words = snapshot->MR_snapshot_saved_available_space -
+ restoring_region->MR_region_available_space;
+ }
+}
+
+
#endif /* MR_USE_REGIONS */
Index: runtime/mercury_region.h
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/runtime/mercury_region.h,v
retrieving revision 1.4
diff -u -r1.4 mercury_region.h
--- runtime/mercury_region.h 15 Oct 2007 16:57:03 -0000 1.4
+++ runtime/mercury_region.h 22 Nov 2007 16:36:10 -0000
@@ -40,21 +40,22 @@
#define MR_REGION_PAGE_SPACE_SIZE 256
/*
-** The following constants should match the values of the Mercury compiler
-** options with corresponding names.
+** NOTE: The following constants *must match* the values of the Mercury
+** compiler options with corresponding names (compiler/options.m). Otherwise,
+** runtime errors likely happen.
*/
-
#define MR_REGION_ITE_FRAME_FIXED_SIZE 4
-
-#define MR_REGION_DISJ_FRAME_FIXED_SIZE 4
-#define MR_REGION_DISJ_FRAME_DUMMY_SEQ_NUMBER 0
-
+#define MR_REGION_DISJ_FRAME_FIXED_SIZE 3
#define MR_REGION_COMMIT_FRAME_FIXED_SIZE 4
-
-#define MR_REGION_SNAPSHOT_SIZE 4
-
#define MR_REGION_ITE_PROT_SIZE 1
+#define MR_REGION_ITE_SNAPSHOT_SIZE 4
+/*
+** The MR_REGION_DISJ_PROT_SIZE is no longer used. It should be removed when
+** the runtime support for RBMM becomes more stable. When removing it
+** remember to make the compiler/options.m consistent with the removal here.
+*/
#define MR_REGION_DISJ_PROT_SIZE 0
+#define MR_REGION_DISJ_SNAPSHOT_SIZE 4
#define MR_REGION_COMMIT_SAVE_SIZE 1
/*
@@ -63,7 +64,6 @@
** fields in this struct is important. We make use of the order for several
** computations (such as the address of a region).
*/
-
struct MR_RegionPage_Struct {
/* The space to store program data. */
MR_Word MR_regionpage_space[MR_REGION_PAGE_SPACE_SIZE];
@@ -86,7 +86,6 @@
** The information of the region itself (pointer to next available word,
** removal counter, some other operational data) is stored in its first page.
*/
-
struct MR_Region_Struct {
/*
** Pointer to the last page of the region, i.e., the newest or last added
@@ -131,7 +130,8 @@
MR_RegionCommitFixedFrame *MR_region_commit_frame;
/*
- ** True if the region has been removed logically in a commit context and
+ ** True if the region is *new* to a commit (i.e., created after the entry
+ ** to the commit), has been removed logically in the commit and
** therefore needs to be destroyed at commit.
*/
MR_Word MR_region_destroy_at_commit;
@@ -140,17 +140,26 @@
MR_Region *MR_region_next_region;
};
+/*---------------------------------------------------------------------------*/
+/*
+** NOTE: The sizes of the next 7 data structures *must match* the Mercury
+** compiler options defined for them in compiler/options.m and also the
+** constants defined above, right in this file.
+** So changes to these data structures, such as removing or adding fields, must
+** be reflected in the other two places.
+** Otherwise, runtime errors likely happen.
+*/
+
struct MR_RegionIteFixedFrame_Struct {
MR_RegionIteFixedFrame *MR_riff_previous_ite_frame;
- MR_Region *MR_riff_saved_region_list;
- int MR_riff_num_prot_regions;
- int MR_riff_num_snapshots;
+ MR_Word MR_riff_saved_sequence_number;
+ MR_Word MR_riff_num_prot_regions;
+ MR_Word MR_riff_num_snapshots;
};
struct MR_RegionDisjFixedFrame_Struct {
MR_RegionDisjFixedFrame *MR_rdff_previous_disj_frame;
- MR_Region *MR_rdff_saved_region_list;
- MR_Word MR_rdff_disj_prot_seq_number;
+ MR_Word MR_rdff_saved_sequence_number;
MR_Word MR_rdff_num_snapshots;
};
@@ -187,11 +196,12 @@
MR_Region *MR_commit_save_region;
};
+/*---------------------------------------------------------------------------*/
+
/*
** The region runtime maintains a list of free pages, when a program needs
** a page for a region the page is taken from the list.
*/
-
extern MR_RegionPage *MR_region_free_page_list;
/* The live regions are linked in a list. */
@@ -250,8 +260,8 @@
new_ite_frame = (MR_RegionIteFixedFrame *) (new_ite_sp); \
new_ite_frame->MR_riff_previous_ite_frame = \
MR_region_ite_sp; \
- new_ite_frame->MR_riff_saved_region_list = \
- MR_live_region_list; \
+ new_ite_frame->MR_riff_saved_sequence_number = \
+ MR_region_sequence_number; \
MR_region_ite_sp = new_ite_frame; \
MR_region_debug_push_ite_frame(new_ite_frame); \
} while (0)
@@ -263,9 +273,7 @@
new_disj_frame = (MR_RegionDisjFixedFrame *) (new_disj_sp); \
new_disj_frame->MR_rdff_previous_disj_frame = \
MR_region_disj_sp; \
- new_disj_frame->MR_rdff_saved_region_list = \
- MR_live_region_list; \
- new_disj_frame->MR_rdff_disj_prot_seq_number = \
+ new_disj_frame->MR_rdff_saved_sequence_number = \
MR_region_sequence_number; \
MR_region_disj_sp = new_disj_frame; \
MR_region_debug_push_disj_frame(new_disj_frame); \
@@ -300,33 +308,39 @@
#define MR_region_fill_ite_protect(ite_sp, region_ptr, \
num_protected_regions, region_slot_reg) \
do { \
- MR_Region *region; \
+ MR_Region *region; \
+ MR_RegionIteProtect *ite_prot; \
\
+ MR_region_debug_start("fill_ite_protect"); \
region = (MR_Region *) (region_ptr); \
if (!MR_region_is_disj_protected(region) && \
region->MR_region_ite_protected == NULL) \
{ \
- *((MR_Word *) (region_slot_reg)) = (MR_Word) region; \
+ ite_prot = (MR_RegionIteProtect *) (region_slot_reg); \
+ ite_prot->MR_ite_prot_region = region; \
(num_protected_regions)++; \
- (region_slot_reg) = (MR_Word) \
- (((MR_Word *) (region_slot_reg)) + \
- MR_REGION_ITE_PROT_SIZE); \
+ (region_slot_reg) = (MR_Word)(ite_prot + 1); \
region->MR_region_ite_protected = \
(MR_RegionIteFixedFrame *) (ite_sp); \
+ MR_region_profile_increase_counter( \
+ &MR_rbmmp_regions_protected_at_ite); \
+ MR_region_debug_fill_ite_protect(ite_prot, region); \
+ } else { \
+ MR_region_debug_fill_ite_protect(NULL, region); \
} \
+ MR_region_debug_end("fill_ite_protect"); \
} while (0)
/*
** This is to prepare for instant reclaiming at the start of else. For instant
** reclaiming a region we save its current size by taking a snapshot of it. The
-** natural question would be for which regions. The very first
-** criterion is whether a region will be destroyed right at the start of the
-** else. It is because we need not to reclaim memory for those which will be
-** destroyed anyway right after that. To decide if a region will be destroyed
-** at the start of the else we need information at both compile-time and
-** runtime. That is at compile-time we only know if the region is removed or
-** not, and at runtime we will know if the region is protected from being
-** destroyed. So,
+** natural question would be for which regions. The very first criterion is
+** whether a region will be destroyed right at the start of the else. It is
+** because we need not to reclaim memory for those which will be destroyed
+** anyway right after that. To decide if a region will be destroyed at the
+** start of the else we need information at both compile-time and runtime. That
+** is at compile-time we only know if the region is removed or not, and at
+** runtime we will know if the region is protected from being destroyed. So,
** 1. Those that are removed and protected need to be saved.
** 2. Those that are not removed (so not destroyed) will need to be saved.
*/
@@ -336,27 +350,49 @@
#define MR_region_fill_ite_snapshot_removed(ite_sp, region_ptr, \
num_snapshots, snapshot_block) \
do { \
- MR_Region *region; \
+ MR_Region *region; \
+ MR_RegionSnapshot *snapshot; \
\
+ MR_region_debug_start( \
+ "fill_ite_snapshot_removed"); \
region = (MR_Region *) (region_ptr); \
+ snapshot = (MR_RegionSnapshot *) (snapshot_block); \
if (region->MR_region_ite_protected != NULL || \
MR_region_is_disj_protected(region)) \
{ \
- MR_save_snapshot(region, snapshot_block); \
- MR_next_snapshot_block(snapshot_block); \
+ MR_save_snapshot(region, snapshot); \
+ MR_region_profile_increase_counter( \
+ &MR_rbmmp_snapshots_saved_at_ite); \
+ (snapshot_block) = (MR_Word) (snapshot + 1); \
(num_snapshots)++; \
- } /* Else the region is not protected. */ \
+ MR_region_debug_fill_ite_snapshot_removed(snapshot, \
+ region); \
+ } else { \
+ /* Else the region is not protected. */ \
+ MR_region_debug_fill_ite_snapshot_removed(NULL, region);\
+ } \
+ MR_region_debug_end("fill_ite_snapshot_removed"); \
} while (0)
#define MR_region_fill_ite_snapshot_not_removed(ite_sp, region_ptr, \
num_snapshots, snapshot_block) \
do { \
- MR_Region *region; \
+ MR_Region *region; \
+ MR_RegionSnapshot *snapshot; \
\
+ MR_region_debug_start( \
+ "fill_ite_snapshot_not_removed"); \
region = (MR_Region *) (region_ptr); \
- MR_save_snapshot(region, (snapshot_block)); \
- MR_next_snapshot_block(snapshot_block); \
+ snapshot = (MR_RegionSnapshot *) (snapshot_block); \
+ MR_save_snapshot(region, snapshot); \
+ MR_region_profile_increase_counter( \
+ &MR_rbmmp_snapshots_saved_at_ite); \
+ (snapshot_block) = (MR_Word) (snapshot + 1); \
(num_snapshots)++; \
+ MR_region_debug_fill_ite_snapshot_not_removed(snapshot, \
+ region); \
+ MR_region_debug_end( \
+ "fill_ite_snapshot_not_removed"); \
} while (0)
#define MR_region_fill_disj_protect(disj_sp, region_ptr, \
@@ -367,12 +403,19 @@
#define MR_region_fill_disj_snapshot(disj_sp, region_ptr, \
num_snapshots, snapshot_block) \
do { \
- MR_Region *region; \
+ MR_Region *region; \
+ MR_RegionSnapshot *snapshot; \
\
+ MR_region_debug_start("fill_disj_snapshot"); \
region = (MR_Region *) (region_ptr); \
- MR_save_snapshot(region, (snapshot_block)); \
- MR_next_snapshot_block(snapshot_block); \
+ snapshot = (MR_RegionSnapshot *) (snapshot_block); \
+ MR_save_snapshot(region, snapshot); \
+ MR_region_profile_increase_counter( \
+ &MR_rbmmp_snapshots_saved_at_disj); \
+ (snapshot_block) = (MR_Word) (snapshot + 1); \
(num_snapshots)++; \
+ MR_region_debug_fill_disj_snapshot(snapshot, region); \
+ MR_region_debug_end("fill_disj_snapshot"); \
} while (0)
/*
@@ -383,20 +426,27 @@
#define MR_region_fill_commit(commit_sp, region_ptr, \
num_saved_region_reg, region_slot_reg) \
do { \
- MR_Region *region; \
+ MR_Region *region; \
+ MR_RegionCommitSave *commit_save; \
\
+ MR_region_debug_start("fill_commit"); \
region = (MR_Region *) (region_ptr); \
if (!MR_region_is_disj_protected(region) && \
region->MR_region_ite_protected == NULL) \
{ \
- *((MR_Word *) (region_slot_reg)) = (MR_Word) region; \
+ commit_save = (MR_RegionCommitSave *) (region_slot_reg);\
+ commit_save->MR_commit_save_region = region; \
num_saved_region_reg++; \
- (region_slot_reg) = (MR_Word) \
- (((MR_Word *) (region_slot_reg)) + \
- MR_REGION_COMMIT_SAVE_SIZE); \
+ (region_slot_reg) = (MR_Word) (commit_save + 1); \
region->MR_region_commit_frame = \
(MR_RegionCommitFixedFrame *) (commit_sp); \
+ MR_region_profile_increase_counter( \
+ &MR_rbmmp_regions_saved_at_commit); \
+ MR_region_debug_fill_commit(commit_save, region); \
+ } else { \
+ MR_region_debug_fill_commit(NULL, region); \
} \
+ MR_region_debug_end("fill_commit"); \
} while (0)
/*---------------------------------------------------------------------------*/
@@ -409,7 +459,6 @@
\
top_ite_frame = (MR_RegionIteFixedFrame *) (ite_sp); \
top_ite_frame->MR_riff_num_prot_regions = (num); \
- MR_region_debug_ite_frame_protected_regions(top_ite_frame); \
} while (0)
#define MR_region_set_ite_num_snapshots(ite_sp, num) \
@@ -418,7 +467,6 @@
\
top_ite_frame = (MR_RegionIteFixedFrame *) (ite_sp); \
top_ite_frame->MR_riff_num_snapshots = (num); \
- MR_region_debug_ite_frame_snapshots(top_ite_frame); \
} while (0)
#define MR_region_set_disj_num_protects(disj_sp, num) \
@@ -431,7 +479,6 @@
\
top_disj_frame = (MR_RegionDisjFixedFrame *) (disj_sp); \
top_disj_frame->MR_rdff_num_snapshots = (num); \
- MR_region_debug_disj_frame_snapshots(top_disj_frame); \
} while (0)
#define MR_region_set_commit_num_entries(commit_sp, num) \
@@ -441,8 +488,6 @@
top_commit_frame = \
(MR_RegionCommitFixedFrame *) (commit_sp); \
top_commit_frame->MR_rcff_num_saved_regions = (num); \
- MR_region_debug_commit_frame_saved_regions( \
- top_commit_frame); \
} while (0)
/*---------------------------------------------------------------------------*/
@@ -465,6 +510,7 @@
MR_RegionIteProtect *ite_prot; \
int i; \
\
+ MR_region_debug_start("use_region_ite_then_semidet"); \
top_ite_frame = (MR_RegionIteFixedFrame *) (ite_sp); \
ite_prot = (MR_RegionIteProtect *) ( (ite_sp) + \
MR_REGION_ITE_FRAME_FIXED_SIZE); \
@@ -474,6 +520,7 @@
ite_prot->MR_ite_prot_region); \
} \
MR_pop_region_ite_frame(top_ite_frame); \
+ MR_region_debug_end("use_region_ite_then_semidet"); \
} while (0)
#define MR_use_region_ite_then_nondet(ite_sp) \
@@ -482,6 +529,7 @@
MR_RegionIteProtect *ite_prot; \
int i; \
\
+ MR_region_debug_start("use_region_ite_then_nondet"); \
top_ite_frame = (MR_RegionIteFixedFrame *) (ite_sp); \
ite_prot = (MR_RegionIteProtect *) ( (ite_sp) + \
MR_REGION_ITE_FRAME_FIXED_SIZE); \
@@ -492,55 +540,82 @@
ite_prot->MR_ite_prot_region); \
} \
} \
+ MR_region_debug_end("use_region_ite_then_nondet"); \
} while (0)
#define MR_use_region_ite_else_semidet(ite_sp) \
do { \
MR_RegionIteFixedFrame *top_ite_frame; \
\
+ MR_region_debug_start("use_region_ite_else_semidet"); \
top_ite_frame = (MR_RegionIteFixedFrame *) (ite_sp); \
MR_region_process_at_ite_else(top_ite_frame); \
+ MR_region_debug_end("use_region_ite_else_semidet"); \
} while (0)
#define MR_use_region_ite_else_nondet(ite_sp) \
do { \
MR_RegionIteFixedFrame *top_ite_frame; \
\
+ MR_region_debug_start("use_region_ite_else_nondet"); \
top_ite_frame = (MR_RegionIteFixedFrame *) (ite_sp); \
MR_region_process_at_ite_else(top_ite_frame); \
+ MR_region_debug_end("use_region_ite_else_nondet"); \
} while (0)
/*
-** XXX What am I supposed to do here?
-** I think it should be exactly the same as the process at the start of
-** any else branch, i.e., after the condition fails (to produce any solution).
+** This is to handle the post-success failure of the condition in an
+** if-then-else with nondet condition.
+** Because the execution will resume at the alternative after the
+** if-then-else:
+** 1. any ite-protected regions here are new regions w.r.t the alternative
+** because old regions w.r.t the alternative is disj-protected and will not
+** be ite-protected here;
+** 2. any new regions here are certainly also new regions to
+** the alternative;
+** 3. new allocations (into regions) here may be into old regions
+** or into new regions to the alternative (but old to the if-then-else).
+** (1) and (2) will be destroyed anyway at the beginning of the alternative.
+** So we do not do anything to them here.
+** For (3) we may want to reclaim only the new allocations into old regions to
+** the alternative, not into the new ones because they will be destroyed
+** anyway.
+** XXX But the implementation below just reclaims them all. That is
+** suboptimal but the cost seems negligible.
+** After that the frame is discarded.
*/
#define MR_use_region_ite_nondet_cond_fail(ite_sp) \
do { \
MR_RegionIteFixedFrame *top_ite_frame; \
\
+ MR_region_debug_start("use_region_ite_nondet_cond_fail"); \
top_ite_frame = (MR_RegionIteFixedFrame *) (ite_sp); \
- MR_region_process_at_ite_else(top_ite_frame) \
+ MR_region_ite_restore_from_snapshots(top_ite_frame); \
+ MR_pop_region_ite_frame(top_ite_frame); \
+ MR_region_debug_end("use_region_ite_nondet_cond_fail"); \
} while (0)
#define MR_use_region_disj_later(disj_sp) \
do { \
MR_RegionDisjFixedFrame *top_disj_frame; \
\
+ MR_region_debug_start("use_region_disj_later"); \
top_disj_frame = (MR_RegionDisjFixedFrame *) (disj_sp); \
MR_region_disj_restore_from_snapshots(top_disj_frame); \
MR_region_disj_destroy_new_regions(top_disj_frame); \
+ MR_region_debug_end("use_region_disj_later"); \
} while (0)
#define MR_use_region_disj_last(disj_sp) \
do { \
MR_RegionDisjFixedFrame *top_disj_frame; \
\
+ MR_region_debug_start("use_region_disj_last"); \
top_disj_frame = (MR_RegionDisjFixedFrame *) (disj_sp); \
MR_region_disj_restore_from_snapshots(top_disj_frame); \
MR_region_disj_destroy_new_regions(top_disj_frame); \
- MR_region_disj_unprotect_regions(top_disj_frame); \
MR_pop_region_disj_frame(top_disj_frame); \
+ MR_region_debug_end("use_region_disj_last"); \
} while (0)
#define MR_use_region_commit_success(commit_sp) \
@@ -548,13 +623,11 @@
MR_RegionCommitFixedFrame *top_commit_frame; \
MR_RegionCommitSave *first_commit_save; \
\
+ MR_region_debug_start("use_region_commit_success"); \
top_commit_frame = \
(MR_RegionCommitFixedFrame *) (commit_sp); \
first_commit_save = (MR_RegionCommitSave *) ( \
(commit_sp) + MR_REGION_COMMIT_FRAME_FIXED_SIZE); \
- \
- MR_region_debug_commit_frame(top_commit_frame); \
- \
MR_commit_success_destroy_marked_new_regions( \
top_commit_frame->MR_rcff_saved_sequence_number); \
MR_commit_success_destroy_marked_saved_regions( \
@@ -562,16 +635,13 @@
first_commit_save); \
MR_region_disj_sp = top_commit_frame->MR_rcff_saved_disj_sp;\
MR_pop_region_commit_frame(top_commit_frame); \
+ MR_region_debug_end("use_region_commit_success"); \
} while (0)
/*
** Commit failure means that the goal in the commit operation has failed.
-** During this execution, all of the regions which are live before and removed
-** inside the commit operation were saved at the commit frame because none of
-** them were protected.
-** We reset any changes to the commit-related state of these saved regions
-** i.e., commit_frame and destroy_at_commit, to NULL and false, respectively.
-** Then the top commit frame is popped.
+** We reset the commit_frame field of the saved regions at the commit frame to
+** NULL. Then the top commit frame is popped.
*/
#define MR_use_region_commit_failure(commit_sp) \
do { \
@@ -580,6 +650,7 @@
MR_Region *region; \
int i; \
\
+ MR_region_debug_start("use_region_commit_failure"); \
top_commit_frame = \
(MR_RegionCommitFixedFrame *) (commit_sp); \
commit_save = (MR_RegionCommitSave *) ( (commit_sp) + \
@@ -589,10 +660,10 @@
region = commit_save->MR_commit_save_region; \
if (region != NULL) { \
region->MR_region_commit_frame = NULL; \
- region->MR_region_destroy_at_commit = MR_FALSE; \
} \
} \
MR_pop_region_commit_frame(top_commit_frame); \
+ MR_region_debug_end("use_region_commit_failure"); \
} while (0)
extern void MR_commit_success_destroy_marked_saved_regions(
@@ -649,19 +720,19 @@
MR_Region *protected_region; \
int i; \
\
- MR_region_debug_ite_frame(top_ite_frame); \
+ MR_region_debug_start("ite_unprotect"); \
ite_prot = (MR_RegionIteProtect *) ( \
( (MR_Word *) (top_ite_frame) ) + \
MR_REGION_ITE_FRAME_FIXED_SIZE); \
for (i = 0; i < top_ite_frame->MR_riff_num_prot_regions; \
i++, ite_prot++) { \
protected_region = ite_prot->MR_ite_prot_region; \
+ MR_region_debug_ite_unprotect(protected_region); \
/* Try to protect the region by an outer condition. */ \
protected_region->MR_region_ite_protected = \
top_ite_frame->MR_riff_previous_ite_frame; \
- MR_region_debug_region_struct_removal_info( \
- protected_region); \
} \
+ MR_region_debug_end("ite_unprotect"); \
} while (0)
#define MR_region_ite_restore_from_snapshots(top_ite_frame) \
@@ -669,6 +740,8 @@
MR_RegionSnapshot *first_snapshot; \
MR_Word protection_size; \
\
+ MR_region_debug_start( \
+ "ite_restore_from_snapshot"); \
protection_size = top_ite_frame->MR_riff_num_prot_regions * \
MR_REGION_ITE_PROT_SIZE; \
first_snapshot = (MR_RegionSnapshot *) ( \
@@ -676,11 +749,19 @@
MR_REGION_ITE_FRAME_FIXED_SIZE + protection_size); \
MR_restore_snapshots(top_ite_frame->MR_riff_num_snapshots, \
first_snapshot); \
+ MR_region_debug_end( \
+ "ite_restore_from_snapshot"); \
} while (0)
#define MR_region_ite_destroy_new_regions(top_ite_frame) \
- MR_region_frame_destroy_new_regions( \
- top_ite_frame->MR_riff_saved_region_list)
+ do { \
+ MR_region_debug_start( \
+ "ite_destroy_new_regions"); \
+ MR_region_frame_destroy_new_regions( \
+ top_ite_frame->MR_riff_saved_sequence_number); \
+ MR_region_debug_end( \
+ "ite_destroy_new_regions"); \
+ } while (0)
/*---------------------------------------------------------------------------*/
/* Helpers for nondet disjunction support. */
@@ -692,11 +773,15 @@
do { \
MR_RegionSnapshot *first_snapshot; \
\
+ MR_region_debug_start( \
+ "disj_restore_from_snapshots"); \
first_snapshot = (MR_RegionSnapshot *) ( \
(MR_Word *) (top_disj_frame) + \
MR_REGION_DISJ_FRAME_FIXED_SIZE); \
MR_restore_snapshots(top_disj_frame->MR_rdff_num_snapshots, \
first_snapshot); \
+ MR_region_debug_end( \
+ "disj_restore_from_snapshots"); \
} while (0)
/*
@@ -704,25 +789,19 @@
** regions.
*/
#define MR_region_disj_destroy_new_regions(top_disj_frame) \
- MR_region_frame_destroy_new_regions( \
- top_disj_frame->MR_rdff_saved_region_list)
-
-/*
-** At the last disjunct, we do not disj-protect the regions anymore.
-*/
-#define MR_region_disj_unprotect_regions(top_disj_frame) \
do { \
- top_disj_frame->MR_rdff_disj_prot_seq_number = \
- MR_REGION_DISJ_FRAME_DUMMY_SEQ_NUMBER; \
+ MR_region_debug_start( \
+ "disj_destroy_new_regions"); \
+ MR_region_frame_destroy_new_regions( \
+ top_disj_frame->MR_rdff_saved_sequence_number); \
+ MR_region_debug_end( \
+ "disj_destroy_new_regions"); \
} while (0)
/*---------------------------------------------------------------------------*/
-#define MR_save_snapshot(region, snapshot_block) \
+#define MR_save_snapshot(region, snapshot) \
do { \
- MR_RegionSnapshot *snapshot; \
- \
- snapshot = (MR_RegionSnapshot *) (snapshot_block); \
snapshot->MR_snapshot_region = (region); \
snapshot->MR_snapshot_saved_last_page = \
(region)->MR_region_last_page; \
@@ -732,11 +811,7 @@
(region)->MR_region_available_space; \
} while (0)
-#define MR_next_snapshot_block(snapshot_block) ( \
- (snapshot_block) = (MR_Word) \
- (((MR_RegionSnapshot *) (snapshot_block) ) + 1) \
- )
-
+
/*
** XXX For profiling:
** One correct way to reset the allocated_size is to save it in the snapshot
@@ -762,6 +837,7 @@
first_new_page = saved_last_page->MR_regionpage_next; \
/* Collect profiling information. */ \
MR_region_profile_restore_from_snapshot(snapshot); \
+ MR_region_debug_restore_from_snapshot(snapshot); \
\
if (first_new_page != NULL) { \
MR_region_return_page_list(first_new_page, \
@@ -776,19 +852,20 @@
} \
} while(0)
-#define MR_region_frame_destroy_new_regions(saved_most_recent_region) \
+#define MR_region_frame_destroy_new_regions(saved_sequence_number) \
do { \
MR_Region *region; \
- MR_Region *next_region; \
\
region = MR_live_region_list; \
- while (region != saved_most_recent_region) { \
- next_region = region->MR_region_next_region; \
- /* We destroy regions upto before the saved one. */ \
+ while (region != NULL && \
+ region->MR_region_sequence_number >= \
+ saved_sequence_number) \
+ { \
MR_region_destroy_region(region); \
- region = next_region; \
+ MR_region_debug_destroy_region(region); \
+ region = region->MR_region_next_region; \
} \
- MR_live_region_list = saved_most_recent_region; \
+ MR_live_region_list = region; \
} while (0)
/* from_page must not be NULL. */
@@ -814,6 +891,9 @@
#define MR_region_debug_destroy_region(region) \
MR_region_destroy_region_msg(region)
+ #define MR_region_debug_logically_remove_region(region) \
+ MR_region_logically_remove_region_msg(region)
+
/* Debug ite frame messages. */
#define MR_region_debug_push_ite_frame(ite_sp) \
MR_region_push_ite_frame_msg(ite_sp)
@@ -821,10 +901,10 @@
#define MR_region_debug_ite_frame(ite_sp); \
MR_region_ite_frame_msg(ite_sp)
- #define MR_region_debug_ite_frame_protected_regions(ite_sp); \
+ #define MR_region_debug_ite_frame_protected_regions(ite_sp) \
MR_region_ite_frame_protected_regions_msg(ite_sp)
- #define MR_region_debug_ite_frame_snapshots(ite_sp); \
+ #define MR_region_debug_ite_frame_snapshots(ite_sp) \
MR_region_ite_frame_snapshots_msg(ite_sp)
/* Debug disj frame messages. */
@@ -834,11 +914,11 @@
#define MR_region_debug_disj_frame(disj_sp) \
MR_region_disj_frame_msg(disj_sp)
- #define MR_region_debug_disj_frame_protected_regions(disj_sp); \
- MR_region_disj_frame_protected_regions_msg(disj_sp);
+ #define MR_region_debug_disj_frame_protected_regions(disj_sp) \
+ MR_region_disj_frame_protected_regions_msg(disj_sp)
- #define MR_region_debug_disj_frame_snapshots(disj_sp); \
- MR_region_disj_frame_snapshots_msg(disj_sp);
+ #define MR_region_debug_disj_frame_snapshots(disj_sp) \
+ MR_region_disj_frame_snapshots_msg(disj_sp)
/* Debug commit frame messages. */
#define MR_region_debug_push_commit_frame(frame) \
@@ -847,9 +927,39 @@
#define MR_region_debug_commit_frame(frame) \
MR_region_commit_frame_msg(frame)
- #define MR_region_debug_commit_frame_saved_regions(commit_sp); \
+ #define MR_region_debug_commit_frame_saved_regions(commit_sp) \
MR_region_commit_frame_saved_regions_msg(commit_sp)
+/* Some other helpers */
+ #define MR_region_debug_start(name) \
+ MR_region_start_msg(name)
+
+ #define MR_region_debug_end(name) \
+ MR_region_end_msg(name)
+
+ #define MR_region_debug_fill_ite_protect(ite_prot, region) \
+ MR_region_fill_ite_protect_msg(ite_prot, region)
+
+ #define MR_region_debug_fill_ite_snapshot_not_removed(snapshot, \
+ region) \
+ MR_region_fill_ite_snapshot_not_removed_msg(snapshot, \
+ region)
+
+ #define MR_region_debug_fill_ite_snapshot_removed(snapshot, region) \
+ MR_region_fill_ite_snapshot_removed_msg(snapshot, region)
+
+ #define MR_region_debug_fill_disj_snapshot(snapshot, region) \
+ MR_region_fill_disj_snapshot_msg(snapshot, region)
+
+ #define MR_region_debug_fill_commit(commit_save, region) \
+ MR_region_fill_commit_msg(commit_save, region)
+
+ #define MR_region_debug_ite_unprotect(protected_region) \
+ MR_region_ite_unprotect_msg(protected_region)
+
+ #define MR_region_debug_restore_from_snapshot(snapshot) \
+ MR_region_restore_from_snapshot_msg(snapshot)
+
#else /* MR_RBMM_DEBUG */
#define MR_region_debug_create_region(region) \
((void) 0)
@@ -857,13 +967,15 @@
#define MR_region_debug_try_remove_region(region) \
((void) 0)
-
#define MR_region_debug_region_struct_removal_info(region) \
((void) 0)
#define MR_region_debug_destroy_region(region) \
((void) 0)
+ #define MR_region_debug_logically_remove_region(region) \
+ ((void) 0)
+
#define MR_region_debug_push_ite_frame(frame) \
((void) 0)
@@ -894,6 +1006,34 @@
#define MR_region_debug_commit_frame_saved_regions(commit_sp) \
((void) 0)
+ #define MR_region_debug_start(name) \
+ ((void) 0)
+
+ #define MR_region_debug_end(name) \
+ ((void) 0)
+
+ #define MR_region_debug_fill_ite_protect(ite_prot, region); \
+ ((void) 0)
+
+ #define MR_region_debug_fill_ite_snapshot_not_removed(snapshot, \
+ region) \
+ ((void) 0)
+
+ #define MR_region_debug_fill_ite_snapshot_removed(snapshot, region) \
+ ((void) 0)
+
+ #define MR_region_debug_fill_disj_snapshot(snapshot, region) \
+ ((void) 0)
+
+ #define MR_region_debug_fill_commit(commit_save, region); \
+ ((void) 0)
+
+ #define MR_region_debug_ite_unprotect(protected_region) \
+ ((void) 0)
+
+ #define MR_region_debug_restore_from_snapshot(snapshot); \
+ ((void) 0)
+
#endif /* MR_RBMM_DEBUG */
extern void MR_region_create_region_msg(MR_Region *region);
@@ -925,6 +1065,21 @@
int saved_seq_number, int number_of_saved_regions,
MR_RegionCommitFixedFrame *commit_frame);
+extern void MR_region_start_msg(const char *);
+extern void MR_region_end_msg(const char *);
+
+extern void MR_region_fill_ite_protect_msg(MR_RegionIteProtect *,
+ MR_Region *);
+extern void MR_region_fill_ite_snapshot_not_removed_msg(
+ MR_RegionSnapshot *, MR_Region *);
+extern void MR_region_fill_ite_snapshot_removed_msg(MR_RegionSnapshot *,
+ MR_Region *);
+extern void MR_region_fill_disj_snapshot_msg(MR_RegionSnapshot *,
+ MR_Region *);
+extern void MR_region_fill_commit_msg(MR_RegionCommitSave *, MR_Region *);
+extern void MR_region_ite_unprotect_msg(MR_Region *);
+extern void MR_region_restore_from_snapshot_msg(MR_RegionSnapshot *);
+
/*---------------------------------------------------------------------------*/
/* Profiling RBMM. */
@@ -957,7 +1112,7 @@
extern MR_RegionProfUnit MR_rbmmp_pages_used;
extern unsigned int MR_rbmmp_page_requested;
extern unsigned int MR_rbmmp_biggest_region_size;
-extern MR_RegionProfUnit MR_rbmmp_regions_saved_at_commit;
+extern unsigned int MR_rbmmp_regions_saved_at_commit;
extern unsigned int MR_rbmmp_regions_protected_at_ite;
extern unsigned int MR_rbmmp_snapshots_saved_at_ite;
extern unsigned int MR_rbmmp_regions_protected_at_disj;
@@ -970,10 +1125,10 @@
MR_RegionProfUnit *profiling_unit, int quantity);
extern void MR_region_profile_destroyed_region(MR_Region *);
extern void MR_region_profile_restore_from_snapshot(MR_RegionSnapshot *);
+extern void MR_region_profile_increase_counter(unsigned int *);
extern int MR_region_get_number_of_pages(MR_RegionPage *,
MR_RegionPage *);
extern void MR_region_print_profiling_info(void);
-
/*---------------------------------------------------------------------------*/
#endif /* MR_USE_REGIONS */
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/c_interface/standalone_c
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/solver_types
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 slice
cvs diff: Diffing ssdb
cvs diff: Diffing tools
cvs diff: Diffing trace
cvs diff: Diffing trax
cvs diff: Diffing trial
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 messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list