aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorYuan Fu2022-11-21 12:54:35 -0800
committerYuan Fu2022-11-21 12:54:35 -0800
commitaaeaa310f0391f5a5193e1a3d6e026986c4f2c0c (patch)
tree67765b95359bfc462e95606043e6b0cea3bb7c49 /src/alloc.c
parentb2ea38ab03e801859163b74a292aa75008e36541 (diff)
parentf176a36f4629b56c9fd9e3fc15aebd04a168c4f5 (diff)
downloademacs-aaeaa310f0391f5a5193e1a3d6e026986c4f2c0c.tar.gz
emacs-aaeaa310f0391f5a5193e1a3d6e026986c4f2c0c.zip
Merge remote-tracking branch 'savannah/master' into feature/tree-sitter
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c67
1 files changed, 46 insertions, 21 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 4b6f9b57b38..0653f2e0ccc 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -1,7 +1,6 @@
1/* Storage allocation and gc for GNU Emacs Lisp interpreter. 1/* Storage allocation and gc for GNU Emacs Lisp interpreter.
2 2
3Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2022 Free Software 3Copyright (C) 1985-2022 Free Software Foundation, Inc.
4Foundation, Inc.
5 4
6This file is part of GNU Emacs. 5This file is part of GNU Emacs.
7 6
@@ -46,6 +45,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
46#include "blockinput.h" 45#include "blockinput.h"
47#include "pdumper.h" 46#include "pdumper.h"
48#include "termhooks.h" /* For struct terminal. */ 47#include "termhooks.h" /* For struct terminal. */
48#include "itree.h"
49#ifdef HAVE_WINDOW_SYSTEM 49#ifdef HAVE_WINDOW_SYSTEM
50#include TERM_HEADER 50#include TERM_HEADER
51#endif /* HAVE_WINDOW_SYSTEM */ 51#endif /* HAVE_WINDOW_SYSTEM */
@@ -3133,6 +3133,11 @@ cleanup_vector (struct Lisp_Vector *vector)
3133 3133
3134 if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_BIGNUM)) 3134 if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_BIGNUM))
3135 mpz_clear (PSEUDOVEC_STRUCT (vector, Lisp_Bignum)->value); 3135 mpz_clear (PSEUDOVEC_STRUCT (vector, Lisp_Bignum)->value);
3136 else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_OVERLAY))
3137 {
3138 struct Lisp_Overlay *ol = PSEUDOVEC_STRUCT (vector, Lisp_Overlay);
3139 xfree (ol->interval);
3140 }
3136 else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_FINALIZER)) 3141 else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_FINALIZER))
3137 unchain_finalizer (PSEUDOVEC_STRUCT (vector, Lisp_Finalizer)); 3142 unchain_finalizer (PSEUDOVEC_STRUCT (vector, Lisp_Finalizer));
3138 else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_FONT)) 3143 else if (PSEUDOVECTOR_TYPEP (&vector->header, PVEC_FONT))
@@ -3707,18 +3712,20 @@ build_symbol_with_pos (Lisp_Object symbol, Lisp_Object position)
3707 return val; 3712 return val;
3708} 3713}
3709 3714
3710/* Return a new overlay with specified START, END and PLIST. */ 3715/* Return a new (deleted) overlay with PLIST. */
3711 3716
3712Lisp_Object 3717Lisp_Object
3713build_overlay (Lisp_Object start, Lisp_Object end, Lisp_Object plist) 3718build_overlay (bool front_advance, bool rear_advance,
3719 Lisp_Object plist)
3714{ 3720{
3715 struct Lisp_Overlay *p = ALLOCATE_PSEUDOVECTOR (struct Lisp_Overlay, plist, 3721 struct Lisp_Overlay *p = ALLOCATE_PSEUDOVECTOR (struct Lisp_Overlay, plist,
3716 PVEC_OVERLAY); 3722 PVEC_OVERLAY);
3717 Lisp_Object overlay = make_lisp_ptr (p, Lisp_Vectorlike); 3723 Lisp_Object overlay = make_lisp_ptr (p, Lisp_Vectorlike);
3718 OVERLAY_START (overlay) = start; 3724 struct itree_node *node = xmalloc (sizeof (*node));
3719 OVERLAY_END (overlay) = end; 3725 itree_node_init (node, front_advance, rear_advance, overlay);
3726 p->interval = node;
3727 p->buffer = NULL;
3720 set_overlay_plist (overlay, plist); 3728 set_overlay_plist (overlay, plist);
3721 p->next = NULL;
3722 return overlay; 3729 return overlay;
3723} 3730}
3724 3731
@@ -5948,8 +5955,7 @@ visit_buffer_root (struct gc_root_visitor visitor,
5948 /* Buffers that are roots don't have intervals, an undo list, or 5955 /* Buffers that are roots don't have intervals, an undo list, or
5949 other constructs that real buffers have. */ 5956 other constructs that real buffers have. */
5950 eassert (buffer->base_buffer == NULL); 5957 eassert (buffer->base_buffer == NULL);
5951 eassert (buffer->overlays_before == NULL); 5958 eassert (buffer->overlays == NULL);
5952 eassert (buffer->overlays_after == NULL);
5953 5959
5954 /* Visit the buffer-locals. */ 5960 /* Visit the buffer-locals. */
5955 visit_vectorlike_root (visitor, (struct Lisp_Vector *) buffer, type); 5961 visit_vectorlike_root (visitor, (struct Lisp_Vector *) buffer, type);
@@ -6505,16 +6511,25 @@ mark_char_table (struct Lisp_Vector *ptr, enum pvec_type pvectype)
6505/* Mark the chain of overlays starting at PTR. */ 6511/* Mark the chain of overlays starting at PTR. */
6506 6512
6507static void 6513static void
6508mark_overlay (struct Lisp_Overlay *ptr) 6514mark_overlay (struct Lisp_Overlay *ov)
6509{ 6515{
6510 for (; ptr && !vectorlike_marked_p (&ptr->header); ptr = ptr->next) 6516 /* We don't mark the `itree_node` object, because it is managed manually
6511 { 6517 rather than by the GC. */
6512 set_vectorlike_marked (&ptr->header); 6518 eassert (BASE_EQ (ov->interval->data, make_lisp_ptr (ov, Lisp_Vectorlike)));
6513 /* These two are always markers and can be marked fast. */ 6519 set_vectorlike_marked (&ov->header);
6514 set_vectorlike_marked (&XMARKER (ptr->start)->header); 6520 mark_object (ov->plist);
6515 set_vectorlike_marked (&XMARKER (ptr->end)->header); 6521}
6516 mark_object (ptr->plist); 6522
6517 } 6523/* Mark the overlay subtree rooted at NODE. */
6524
6525static void
6526mark_overlays (struct itree_node *node)
6527{
6528 if (node == NULL)
6529 return;
6530 mark_object (node->data);
6531 mark_overlays (node->left);
6532 mark_overlays (node->right);
6518} 6533}
6519 6534
6520/* Mark Lisp_Objects and special pointers in BUFFER. */ 6535/* Mark Lisp_Objects and special pointers in BUFFER. */
@@ -6538,8 +6553,8 @@ mark_buffer (struct buffer *buffer)
6538 if (!BUFFER_LIVE_P (buffer)) 6553 if (!BUFFER_LIVE_P (buffer))
6539 mark_object (BVAR (buffer, undo_list)); 6554 mark_object (BVAR (buffer, undo_list));
6540 6555
6541 mark_overlay (buffer->overlays_before); 6556 if (buffer->overlays)
6542 mark_overlay (buffer->overlays_after); 6557 mark_overlays (buffer->overlays->root);
6543 6558
6544 /* If this is an indirect buffer, mark its base buffer. */ 6559 /* If this is an indirect buffer, mark its base buffer. */
6545 if (buffer->base_buffer && 6560 if (buffer->base_buffer &&
@@ -7770,13 +7785,23 @@ allocated since the last garbage collection. All data types count.
7770Garbage collection happens automatically only when `eval' is called. 7785Garbage collection happens automatically only when `eval' is called.
7771 7786
7772By binding this temporarily to a large number, you can effectively 7787By binding this temporarily to a large number, you can effectively
7773prevent garbage collection during a part of the program. 7788prevent garbage collection during a part of the program. But be
7789sure to get back to the normal value soon enough, to avoid system-wide
7790memory pressure, and never use a too-high value for prolonged periods
7791of time.
7774See also `gc-cons-percentage'. */); 7792See also `gc-cons-percentage'. */);
7775 7793
7776 DEFVAR_LISP ("gc-cons-percentage", Vgc_cons_percentage, 7794 DEFVAR_LISP ("gc-cons-percentage", Vgc_cons_percentage,
7777 doc: /* Portion of the heap used for allocation. 7795 doc: /* Portion of the heap used for allocation.
7778Garbage collection can happen automatically once this portion of the heap 7796Garbage collection can happen automatically once this portion of the heap
7779has been allocated since the last garbage collection. 7797has been allocated since the last garbage collection.
7798
7799By binding this temporarily to a large number, you can effectively
7800prevent garbage collection during a part of the program. But be
7801sure to get back to the normal value soon enough, to avoid system-wide
7802memory pressure, and never use a too-high value for prolonged periods
7803of time.
7804
7780If this portion is smaller than `gc-cons-threshold', this is ignored. */); 7805If this portion is smaller than `gc-cons-threshold', this is ignored. */);
7781 Vgc_cons_percentage = make_float (0.1); 7806 Vgc_cons_percentage = make_float (0.1);
7782 7807