44ddf94b24dad9e505796d536d2d0c6f99417e14
[mono.git] / mono / sgen / sgen-layout-stats.c
1 /*
2  * Copyright Xamarin Inc (http://www.xamarin.com)
3  *
4  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
5  */
6
7 #include "config.h"
8 #ifdef HAVE_SGEN_GC
9
10 #include "sgen/sgen-gc.h"
11 #include "sgen/sgen-layout-stats.h"
12
13 #ifdef SGEN_OBJECT_LAYOUT_STATISTICS
14
15 #define NUM_HISTOGRAM_ENTRIES   (1 << SGEN_OBJECT_LAYOUT_BITMAP_BITS)
16
17 static unsigned long histogram [NUM_HISTOGRAM_ENTRIES];
18 static unsigned long count_bitmap_overflow;
19 static unsigned long count_ref_array;
20 static unsigned long count_vtype_array;
21
22 void
23 sgen_object_layout_scanned_bitmap (unsigned int bitmap)
24 {
25         g_assert (!(bitmap >> SGEN_OBJECT_LAYOUT_BITMAP_BITS));
26         ++histogram [bitmap];
27 }
28
29 void
30 sgen_object_layout_scanned_bitmap_overflow (void)
31 {
32         ++count_bitmap_overflow;
33 }
34
35 void
36 sgen_object_layout_scanned_ref_array (void)
37 {
38         ++count_ref_array;
39 }
40
41 void
42 sgen_object_layout_scanned_vtype_array (void)
43 {
44         ++count_vtype_array;
45 }
46
47 void
48 sgen_object_layout_dump (FILE *out)
49 {
50         int i;
51
52         for (i = 0; i < NUM_HISTOGRAM_ENTRIES; ++i) {
53                 if (!histogram [i])
54                         continue;
55                 fprintf (out, "%d %lu\n", i, histogram [i]);
56         }
57         fprintf (out, "bitmap-overflow %lu\n", count_bitmap_overflow);
58         fprintf (out, "ref-array %lu\n", count_ref_array);
59         fprintf (out, "vtype-array %lu\n", count_vtype_array);
60 }
61 #else
62
63 #ifdef _MSC_VER
64 // Quiet Visual Studio linker warning, LNK4221, in cases when this source file intentional ends up empty.
65 void __mono_win32_sgen_layout_stats_quiet_lnk4221(void) {}
66 #endif
67 #endif /* SGEN_OBJECT_LAYOUT_STATISTICS */
68 #endif