2f9ca117783ea2921c5379cd5dfeb202c6a3ea62
[mono.git] / mono / sgen / sgen-layout-stats.c
1 /*
2  * Copyright Xamarin Inc (http://www.xamarin.com)
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23
24 #include "config.h"
25 #ifdef HAVE_SGEN_GC
26
27 #include "sgen/sgen-gc.h"
28 #include "sgen/sgen-layout-stats.h"
29
30 #ifdef SGEN_OBJECT_LAYOUT_STATISTICS
31
32 #define NUM_HISTOGRAM_ENTRIES   (1 << SGEN_OBJECT_LAYOUT_BITMAP_BITS)
33
34 static unsigned long histogram [NUM_HISTOGRAM_ENTRIES];
35 static unsigned long count_bitmap_overflow;
36 static unsigned long count_ref_array;
37 static unsigned long count_vtype_array;
38
39 void
40 sgen_object_layout_scanned_bitmap (unsigned int bitmap)
41 {
42         g_assert (!(bitmap >> SGEN_OBJECT_LAYOUT_BITMAP_BITS));
43         ++histogram [bitmap];
44 }
45
46 void
47 sgen_object_layout_scanned_bitmap_overflow (void)
48 {
49         ++count_bitmap_overflow;
50 }
51
52 void
53 sgen_object_layout_scanned_ref_array (void)
54 {
55         ++count_ref_array;
56 }
57
58 void
59 sgen_object_layout_scanned_vtype_array (void)
60 {
61         ++count_vtype_array;
62 }
63
64 void
65 sgen_object_layout_dump (FILE *out)
66 {
67         int i;
68
69         for (i = 0; i < NUM_HISTOGRAM_ENTRIES; ++i) {
70                 if (!histogram [i])
71                         continue;
72                 fprintf (out, "%d %lu\n", i, histogram [i]);
73         }
74         fprintf (out, "bitmap-overflow %lu\n", count_bitmap_overflow);
75         fprintf (out, "ref-array %lu\n", count_ref_array);
76         fprintf (out, "vtype-array %lu\n", count_vtype_array);
77 }
78
79 #endif
80 #endif