comparison src/alloc.c @ 84978:33b7fe948502

(enum mem_type): Replace all vector subtypes -> MEM_TYPE_VECTORLIKE. (allocate_vectorlike): Remove type argument. Adjust callers. (live_vector_p, mark_maybe_pointer, valid_lisp_object_p): Only handle the one remaining MEM_TYPE_VECTORLIKE. (mark_terminal): Remove left-over declaration.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 29 Sep 2007 20:19:41 +0000
parents 3747382d60e9
children 21a145f18ed2
comparison
equal deleted inserted replaced
84977:3747382d60e9 84978:33b7fe948502
340 340
341 Lisp_Object Vgc_elapsed; /* accumulated elapsed time in GC */ 341 Lisp_Object Vgc_elapsed; /* accumulated elapsed time in GC */
342 EMACS_INT gcs_done; /* accumulated GCs */ 342 EMACS_INT gcs_done; /* accumulated GCs */
343 343
344 static void mark_buffer P_ ((Lisp_Object)); 344 static void mark_buffer P_ ((Lisp_Object));
345 static void mark_terminal P_((struct terminal *t));
346 static void mark_terminals P_ ((void)); 345 static void mark_terminals P_ ((void));
347 extern void mark_kboards P_ ((void)); 346 extern void mark_kboards P_ ((void));
348 extern void mark_ttys P_ ((void)); 347 extern void mark_ttys P_ ((void));
349 extern void mark_backtrace P_ ((void)); 348 extern void mark_backtrace P_ ((void));
350 static void gc_sweep P_ ((void)); 349 static void gc_sweep P_ ((void));
375 MEM_TYPE_CONS, 374 MEM_TYPE_CONS,
376 MEM_TYPE_STRING, 375 MEM_TYPE_STRING,
377 MEM_TYPE_MISC, 376 MEM_TYPE_MISC,
378 MEM_TYPE_SYMBOL, 377 MEM_TYPE_SYMBOL,
379 MEM_TYPE_FLOAT, 378 MEM_TYPE_FLOAT,
380 /* Keep the following vector-like types together, with 379 /* We used to keep separate mem_types for subtypes of vectors such as
381 MEM_TYPE_WINDOW being the last, and MEM_TYPE_VECTOR the 380 process, hash_table, frame, terminal, and window, but we never made
382 first. Or change the code of live_vector_p, for instance. */ 381 use of the distinction, so it only caused source-code complexity
383 MEM_TYPE_VECTOR, 382 and runtime slowdown. Minor but pointless. */
384 MEM_TYPE_PROCESS, 383 MEM_TYPE_VECTORLIKE
385 MEM_TYPE_HASH_TABLE,
386 MEM_TYPE_FRAME,
387 MEM_TYPE_TERMINAL,
388 MEM_TYPE_WINDOW
389 }; 384 };
390 385
391 static POINTER_TYPE *lisp_align_malloc P_ ((size_t, enum mem_type)); 386 static POINTER_TYPE *lisp_align_malloc P_ ((size_t, enum mem_type));
392 static POINTER_TYPE *lisp_malloc P_ ((size_t, enum mem_type)); 387 static POINTER_TYPE *lisp_malloc P_ ((size_t, enum mem_type));
393 void refill_memory_reserve (); 388 void refill_memory_reserve ();
470 465
471 static struct mem_node mem_z; 466 static struct mem_node mem_z;
472 #define MEM_NIL &mem_z 467 #define MEM_NIL &mem_z
473 468
474 static POINTER_TYPE *lisp_malloc P_ ((size_t, enum mem_type)); 469 static POINTER_TYPE *lisp_malloc P_ ((size_t, enum mem_type));
475 static struct Lisp_Vector *allocate_vectorlike P_ ((EMACS_INT, enum mem_type)); 470 static struct Lisp_Vector *allocate_vectorlike P_ ((EMACS_INT));
476 static void lisp_free P_ ((POINTER_TYPE *)); 471 static void lisp_free P_ ((POINTER_TYPE *));
477 static void mark_stack P_ ((void)); 472 static void mark_stack P_ ((void));
478 static int live_vector_p P_ ((struct mem_node *, void *)); 473 static int live_vector_p P_ ((struct mem_node *, void *));
479 static int live_buffer_p P_ ((struct mem_node *, void *)); 474 static int live_buffer_p P_ ((struct mem_node *, void *));
480 static int live_string_p P_ ((struct mem_node *, void *)); 475 static int live_string_p P_ ((struct mem_node *, void *));
2913 2908
2914 /* Value is a pointer to a newly allocated Lisp_Vector structure 2909 /* Value is a pointer to a newly allocated Lisp_Vector structure
2915 with room for LEN Lisp_Objects. */ 2910 with room for LEN Lisp_Objects. */
2916 2911
2917 static struct Lisp_Vector * 2912 static struct Lisp_Vector *
2918 allocate_vectorlike (len, type) 2913 allocate_vectorlike (len)
2919 EMACS_INT len; 2914 EMACS_INT len;
2920 enum mem_type type;
2921 { 2915 {
2922 struct Lisp_Vector *p; 2916 struct Lisp_Vector *p;
2923 size_t nbytes; 2917 size_t nbytes;
2924 2918
2925 MALLOC_BLOCK_INPUT; 2919 MALLOC_BLOCK_INPUT;
2933 2927
2934 /* This gets triggered by code which I haven't bothered to fix. --Stef */ 2928 /* This gets triggered by code which I haven't bothered to fix. --Stef */
2935 /* eassert (!handling_signal); */ 2929 /* eassert (!handling_signal); */
2936 2930
2937 nbytes = sizeof *p + (len - 1) * sizeof p->contents[0]; 2931 nbytes = sizeof *p + (len - 1) * sizeof p->contents[0];
2938 p = (struct Lisp_Vector *) lisp_malloc (nbytes, type); 2932 p = (struct Lisp_Vector *) lisp_malloc (nbytes, MEM_TYPE_VECTORLIKE);
2939 2933
2940 #ifdef DOUG_LEA_MALLOC 2934 #ifdef DOUG_LEA_MALLOC
2941 /* Back to a reasonable maximum of mmap'ed areas. */ 2935 /* Back to a reasonable maximum of mmap'ed areas. */
2942 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); 2936 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS);
2943 #endif 2937 #endif
2959 2953
2960 struct Lisp_Vector * 2954 struct Lisp_Vector *
2961 allocate_vector (nslots) 2955 allocate_vector (nslots)
2962 EMACS_INT nslots; 2956 EMACS_INT nslots;
2963 { 2957 {
2964 struct Lisp_Vector *v = allocate_vectorlike (nslots, MEM_TYPE_VECTOR); 2958 struct Lisp_Vector *v = allocate_vectorlike (nslots);
2965 v->size = nslots; 2959 v->size = nslots;
2966 return v; 2960 return v;
2967 } 2961 }
2968 2962
2969 2963
2971 2965
2972 struct Lisp_Hash_Table * 2966 struct Lisp_Hash_Table *
2973 allocate_hash_table () 2967 allocate_hash_table ()
2974 { 2968 {
2975 EMACS_INT len = VECSIZE (struct Lisp_Hash_Table); 2969 EMACS_INT len = VECSIZE (struct Lisp_Hash_Table);
2976 struct Lisp_Vector *v = allocate_vectorlike (len, MEM_TYPE_HASH_TABLE); 2970 struct Lisp_Vector *v = allocate_vectorlike (len);
2977 EMACS_INT i; 2971 EMACS_INT i;
2978 2972
2979 v->size = len; 2973 v->size = len;
2980 for (i = 0; i < len; ++i) 2974 for (i = 0; i < len; ++i)
2981 v->contents[i] = Qnil; 2975 v->contents[i] = Qnil;
2986 2980
2987 struct window * 2981 struct window *
2988 allocate_window () 2982 allocate_window ()
2989 { 2983 {
2990 EMACS_INT len = VECSIZE (struct window); 2984 EMACS_INT len = VECSIZE (struct window);
2991 struct Lisp_Vector *v = allocate_vectorlike (len, MEM_TYPE_WINDOW); 2985 struct Lisp_Vector *v = allocate_vectorlike (len);
2992 EMACS_INT i; 2986 EMACS_INT i;
2993 2987
2994 for (i = 0; i < len; ++i) 2988 for (i = 0; i < len; ++i)
2995 v->contents[i] = Qnil; 2989 v->contents[i] = Qnil;
2996 v->size = len; 2990 v->size = len;
3005 /* Memory-footprint of the object in nb of Lisp_Object fields. */ 2999 /* Memory-footprint of the object in nb of Lisp_Object fields. */
3006 EMACS_INT memlen = VECSIZE (struct terminal); 3000 EMACS_INT memlen = VECSIZE (struct terminal);
3007 /* Size if we only count the actual Lisp_Object fields (which need to be 3001 /* Size if we only count the actual Lisp_Object fields (which need to be
3008 traced by the GC). */ 3002 traced by the GC). */
3009 EMACS_INT lisplen = PSEUDOVECSIZE (struct terminal, next_terminal); 3003 EMACS_INT lisplen = PSEUDOVECSIZE (struct terminal, next_terminal);
3010 struct Lisp_Vector *v = allocate_vectorlike (memlen, MEM_TYPE_TERMINAL); 3004 struct Lisp_Vector *v = allocate_vectorlike (memlen);
3011 EMACS_INT i; 3005 EMACS_INT i;
3012 Lisp_Object tmp, zero = make_number (0); 3006 Lisp_Object tmp, zero = make_number (0);
3013 3007
3014 for (i = 0; i < lisplen; ++i) 3008 for (i = 0; i < lisplen; ++i)
3015 v->contents[i] = Qnil; 3009 v->contents[i] = Qnil;
3023 3017
3024 struct frame * 3018 struct frame *
3025 allocate_frame () 3019 allocate_frame ()
3026 { 3020 {
3027 EMACS_INT len = VECSIZE (struct frame); 3021 EMACS_INT len = VECSIZE (struct frame);
3028 struct Lisp_Vector *v = allocate_vectorlike (len, MEM_TYPE_FRAME); 3022 struct Lisp_Vector *v = allocate_vectorlike (len);
3029 EMACS_INT i; 3023 EMACS_INT i;
3030 3024
3031 for (i = 0; i < len; ++i) 3025 for (i = 0; i < len; ++i)
3032 v->contents[i] = make_number (0); 3026 v->contents[i] = make_number (0);
3033 v->size = len; 3027 v->size = len;
3041 /* Memory-footprint of the object in nb of Lisp_Object fields. */ 3035 /* Memory-footprint of the object in nb of Lisp_Object fields. */
3042 EMACS_INT memlen = VECSIZE (struct Lisp_Process); 3036 EMACS_INT memlen = VECSIZE (struct Lisp_Process);
3043 /* Size if we only count the actual Lisp_Object fields (which need to be 3037 /* Size if we only count the actual Lisp_Object fields (which need to be
3044 traced by the GC). */ 3038 traced by the GC). */
3045 EMACS_INT lisplen = PSEUDOVECSIZE (struct Lisp_Process, pid); 3039 EMACS_INT lisplen = PSEUDOVECSIZE (struct Lisp_Process, pid);
3046 struct Lisp_Vector *v = allocate_vectorlike (memlen, MEM_TYPE_PROCESS); 3040 struct Lisp_Vector *v = allocate_vectorlike (memlen);
3047 EMACS_INT i; 3041 EMACS_INT i;
3048 3042
3049 for (i = 0; i < lisplen; ++i) 3043 for (i = 0; i < lisplen; ++i)
3050 v->contents[i] = Qnil; 3044 v->contents[i] = Qnil;
3051 v->size = lisplen; 3045 v->size = lisplen;
3056 3050
3057 struct Lisp_Vector * 3051 struct Lisp_Vector *
3058 allocate_other_vector (len) 3052 allocate_other_vector (len)
3059 EMACS_INT len; 3053 EMACS_INT len;
3060 { 3054 {
3061 struct Lisp_Vector *v = allocate_vectorlike (len, MEM_TYPE_VECTOR); 3055 struct Lisp_Vector *v = allocate_vectorlike (len);
3062 EMACS_INT i; 3056 EMACS_INT i;
3063 3057
3064 for (i = 0; i < len; ++i) 3058 for (i = 0; i < len; ++i)
3065 v->contents[i] = Qnil; 3059 v->contents[i] = Qnil;
3066 v->size = len; 3060 v->size = len;
4110 static INLINE int 4104 static INLINE int
4111 live_vector_p (m, p) 4105 live_vector_p (m, p)
4112 struct mem_node *m; 4106 struct mem_node *m;
4113 void *p; 4107 void *p;
4114 { 4108 {
4115 return (p == m->start 4109 return (p == m->start && m->type == MEM_TYPE_VECTORLIKE);
4116 && m->type >= MEM_TYPE_VECTOR
4117 && m->type <= MEM_TYPE_WINDOW);
4118 } 4110 }
4119 4111
4120 4112
4121 /* Value is non-zero if P is a pointer to a live buffer. M is a 4113 /* Value is non-zero if P is a pointer to a live buffer. M is a
4122 pointer to the mem_block for P. */ 4114 pointer to the mem_block for P. */
4310 case MEM_TYPE_FLOAT: 4302 case MEM_TYPE_FLOAT:
4311 if (live_float_p (m, p) && !FLOAT_MARKED_P (p)) 4303 if (live_float_p (m, p) && !FLOAT_MARKED_P (p))
4312 XSETFLOAT (obj, p); 4304 XSETFLOAT (obj, p);
4313 break; 4305 break;
4314 4306
4315 case MEM_TYPE_VECTOR: 4307 case MEM_TYPE_VECTORLIKE:
4316 case MEM_TYPE_PROCESS:
4317 case MEM_TYPE_HASH_TABLE:
4318 case MEM_TYPE_FRAME:
4319 case MEM_TYPE_TERMINAL:
4320 case MEM_TYPE_WINDOW:
4321 if (live_vector_p (m, p)) 4308 if (live_vector_p (m, p))
4322 { 4309 {
4323 Lisp_Object tem; 4310 Lisp_Object tem;
4324 XSETVECTOR (tem, p); 4311 XSETVECTOR (tem, p);
4325 if (!GC_SUBRP (tem) && !VECTOR_MARKED_P (XVECTOR (tem))) 4312 if (!GC_SUBRP (tem) && !VECTOR_MARKED_P (XVECTOR (tem)))
4715 return live_symbol_p (m, p); 4702 return live_symbol_p (m, p);
4716 4703
4717 case MEM_TYPE_FLOAT: 4704 case MEM_TYPE_FLOAT:
4718 return live_float_p (m, p); 4705 return live_float_p (m, p);
4719 4706
4720 case MEM_TYPE_VECTOR: 4707 case MEM_TYPE_VECTORLIKE:
4721 case MEM_TYPE_PROCESS:
4722 case MEM_TYPE_HASH_TABLE:
4723 case MEM_TYPE_FRAME:
4724 case MEM_TYPE_TERMINAL:
4725 case MEM_TYPE_WINDOW:
4726 return live_vector_p (m, p); 4708 return live_vector_p (m, p);
4727 4709
4728 default: 4710 default:
4729 break; 4711 break;
4730 } 4712 }