aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJim Blandy1993-07-18 06:26:10 +0000
committerJim Blandy1993-07-18 06:26:10 +0000
commite87206440141f2cad44d913dd558edc7f60a17cb (patch)
treee91a70156e9f3e46a220747321d78beff160ab10 /src
parent718ca51e403c565c8cb35fbf7f4eb6bb00fee0b8 (diff)
downloademacs-e87206440141f2cad44d913dd558edc7f60a17cb.tar.gz
emacs-e87206440141f2cad44d913dd558edc7f60a17cb.zip
Consistently use the mark bit of the root interval's parent field
to say whether or not the interval tree has been visited (and skip it when revisited), and the mark bit of the plist field to say whether or not that interval has been visited (and abort if revisited); don't try to use the plist mark bit for both meanings. * alloc.c (mark_interval_tree): Don't test if the interval tree has already been visited here; let the MARK_INTERVAL_TREE macro do that; avoid function call overhead. Mark the interval tree as having been visited by setting TREE->parent's mark bit. (MARK_INTERVAL_TREE): If the tree has been visited (according to I->parent's mark bit), don't call mark_interval_tree. (gc_sweep): Rebalance the interval trees of those large strings which are still alive. This also clears the mark bits of those trees' root intervals' parent fields. (compact_strings): Rebalance the interval tree of each small strings which is still alive. This also clears the mark bits of that tree's root interval's parent field. Since the string has moved, update the root interval's parent pointer to contain the new address. * lisp.h (struct interval): Doc fix; explain the roles of the mark bits of the parent and plist members.
Diffstat (limited to 'src')
-rw-r--r--src/alloc.c66
-rw-r--r--src/lisp.h20
2 files changed, 62 insertions, 24 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 07775391bfb..93146526118 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -349,14 +349,23 @@ static void
349mark_interval_tree (tree) 349mark_interval_tree (tree)
350 register INTERVAL tree; 350 register INTERVAL tree;
351{ 351{
352 if (XMARKBIT (tree->plist)) 352 /* No need to test if this tree has been marked already; this
353 return; 353 function is always called through the MARK_INTERVAL_TREE macro,
354 which takes care of that. */
355
356 /* XMARK expands to an assignment; the LHS of an assignment can't be
357 a cast. */
358 XMARK (* (Lisp_Object *) &tree->parent);
354 359
355 traverse_intervals (tree, 1, 0, mark_interval, Qnil); 360 traverse_intervals (tree, 1, 0, mark_interval, Qnil);
356} 361}
357 362
358#define MARK_INTERVAL_TREE(i) \ 363#define MARK_INTERVAL_TREE(i) \
359 { if (!NULL_INTERVAL_P (i)) mark_interval_tree (i); } 364 do { \
365 if (!NULL_INTERVAL_P (i) \
366 && ! XMARKBIT ((Lisp_Object) i->parent)) \
367 mark_interval_tree (i); \
368 } while (0)
360 369
361/* The oddity in the call to XUNMARK is necessary because XUNMARK 370/* The oddity in the call to XUNMARK is necessary because XUNMARK
362 expands to an assignment to its argument, and most C compilers don't 371 expands to an assignment to its argument, and most C compilers don't
@@ -1957,25 +1966,30 @@ gc_sweep ()
1957 /* Free all "large strings" not marked with ARRAY_MARK_FLAG. */ 1966 /* Free all "large strings" not marked with ARRAY_MARK_FLAG. */
1958 { 1967 {
1959 register struct string_block *sb = large_string_blocks, *prev = 0, *next; 1968 register struct string_block *sb = large_string_blocks, *prev = 0, *next;
1969 struct Lisp_String *s;
1960 1970
1961 while (sb) 1971 while (sb)
1962 if (!(((struct Lisp_String *)(&sb->chars[0]))->size & ARRAY_MARK_FLAG)) 1972 {
1963 { 1973 s = (struct Lisp_String *) &sb->chars[0];
1964 if (prev) 1974 if (s->size & ARRAY_MARK_FLAG)
1965 prev->next = sb->next; 1975 {
1966 else 1976 ((struct Lisp_String *)(&sb->chars[0]))->size
1967 large_string_blocks = sb->next; 1977 &= ~ARRAY_MARK_FLAG & ~MARKBIT;
1968 next = sb->next; 1978 UNMARK_BALANCE_INTERVALS (s->intervals);
1969 xfree (sb); 1979 total_string_size += ((struct Lisp_String *)(&sb->chars[0]))->size;
1970 sb = next; 1980 prev = sb, sb = sb->next;
1971 } 1981 }
1972 else 1982 else
1973 { 1983 {
1974 ((struct Lisp_String *)(&sb->chars[0]))->size 1984 if (prev)
1975 &= ~ARRAY_MARK_FLAG & ~MARKBIT; 1985 prev->next = sb->next;
1976 total_string_size += ((struct Lisp_String *)(&sb->chars[0]))->size; 1986 else
1977 prev = sb, sb = sb->next; 1987 large_string_blocks = sb->next;
1978 } 1988 next = sb->next;
1989 xfree (sb);
1990 sb = next;
1991 }
1992 }
1979 } 1993 }
1980} 1994}
1981 1995
@@ -2067,6 +2081,16 @@ compact_strings ()
2067 } 2081 }
2068 /* Store the actual size in the size field. */ 2082 /* Store the actual size in the size field. */
2069 newaddr->size = size; 2083 newaddr->size = size;
2084
2085 /* Now that the string has been relocated, rebalance its
2086 interval tree, and update the tree's parent pointer. */
2087 if (! NULL_INTERVAL_P (newaddr->intervals))
2088 {
2089 UNMARK_BALANCE_INTERVALS (newaddr->intervals);
2090 XSET (* (Lisp_Object *) &newaddr->intervals->parent,
2091 Lisp_String,
2092 newaddr);
2093 }
2070 } 2094 }
2071 pos += STRING_FULLSIZE (size); 2095 pos += STRING_FULLSIZE (size);
2072 } 2096 }
diff --git a/src/lisp.h b/src/lisp.h
index c34dc54d7bc..8d6d00c9981 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -447,8 +447,18 @@ struct interval
447 unsigned int position; /* Cache of interval's character position */ 447 unsigned int position; /* Cache of interval's character position */
448 struct interval *left; /* Intervals which precede me. */ 448 struct interval *left; /* Intervals which precede me. */
449 struct interval *right; /* Intervals which succeed me. */ 449 struct interval *right; /* Intervals which succeed me. */
450 struct interval *parent; /* Parent in the tree, or the Lisp_Object 450
451 containing this interval tree. */ 451 /* Parent in the tree, or the Lisp_Object containing this interval tree.
452
453 The mark bit on the root interval of an interval tree says
454 whether we have started (and possibly finished) marking the
455 tree. If GC comes across an interval tree whose root's parent
456 field has its markbit set, it leaves the tree alone.
457
458 You'd think we could store this information in the parent object
459 somewhere (after all, that should be visited once and then
460 ignored too, right?), but strings are GC'd strangely. */
461 struct interval *parent;
452 462
453 /* The remaining components are `properties' of the interval. 463 /* The remaining components are `properties' of the interval.
454 The first four are duplicates for things which can be on the list, 464 The first four are duplicates for things which can be on the list,
@@ -460,7 +470,11 @@ struct interval
460 before this interval goes into it. */ 470 before this interval goes into it. */
461 unsigned char rear_sticky; /* Likewise for just after it. */ 471 unsigned char rear_sticky; /* Likewise for just after it. */
462 472
463 Lisp_Object plist; /* Properties of this interval. */ 473 /* Properties of this interval.
474 The mark bit on this field says whether this particular interval
475 tree node has been visited. Since intervals should never be
476 shared, GC aborts if it seems to have visited an interval twice. */
477 Lisp_Object plist;
464}; 478};
465 479
466typedef struct interval *INTERVAL; 480typedef struct interval *INTERVAL;