2010-03-12 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / metadata / sgen-pinning.c
blob77a822f49b575f150d697bde28cd1ddacceab995
1 #define PIN_STAGING_AREA_SIZE 1024
3 static void* pin_staging_area [PIN_STAGING_AREA_SIZE];
4 static int pin_staging_area_index;
6 static void
7 init_pinning (void)
9 pin_staging_area_index = 0;
12 static void
13 evacuate_pin_staging_area (void)
15 int i;
17 g_assert (pin_staging_area_index >= 0 && pin_staging_area_index <= PIN_STAGING_AREA_SIZE);
19 if (pin_staging_area_index == 0)
20 return;
23 * The pinning addresses might come from undefined memory, this is normal. Since they
24 * are used in lots of functions, we make the memory defined here instead of having
25 * to add a supression for those functions.
27 VALGRIND_MAKE_MEM_DEFINED (pin_staging_area, pin_staging_area_index * sizeof (void*));
29 sort_addresses (pin_staging_area, pin_staging_area_index);
31 while (next_pin_slot + pin_staging_area_index > pin_queue_size)
32 realloc_pin_queue ();
34 pin_queue [next_pin_slot++] = pin_staging_area [0];
35 for (i = 1; i < pin_staging_area_index; ++i) {
36 void *p = pin_staging_area [i];
37 if (p != pin_queue [next_pin_slot - 1])
38 pin_queue [next_pin_slot++] = p;
41 g_assert (next_pin_slot <= pin_queue_size);
43 pin_staging_area_index = 0;
46 static void
47 pin_stage_ptr (void *ptr)
49 if (pin_staging_area_index >= PIN_STAGING_AREA_SIZE)
50 evacuate_pin_staging_area ();
52 pin_staging_area [pin_staging_area_index++] = ptr;