New tests.
[mono.git] / mono / metadata / sgen-pinning-stats.c
index 4f1998513da86288ea78ee386f4c6e61233038e2..68871c75f6ad6b916dda988d7c87d8aabca67d48 100644 (file)
@@ -1,3 +1,26 @@
+/*
+ * Copyright 2001-2003 Ximian, Inc
+ * Copyright 2003-2010 Novell, Inc.
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
 enum {
        PIN_TYPE_STACK,
        PIN_TYPE_STATIC_DATA,
@@ -13,9 +36,17 @@ struct _PinStatAddress {
        PinStatAddress *right;
 };
 
+typedef struct _ObjectList ObjectList;
+struct _ObjectList {
+       MonoObject *obj;
+       ObjectList *next;
+};
+
 static PinStatAddress *pin_stat_addresses = NULL;
 static size_t pinned_byte_counts [PIN_TYPE_MAX];
 
+static ObjectList *pinned_objects = NULL;
+
 static void
 pin_stats_tree_free (PinStatAddress *node)
 {
@@ -34,6 +65,11 @@ pin_stats_reset (void)
        pin_stat_addresses = NULL;
        for (i = 0; i < PIN_TYPE_MAX; ++i)
                pinned_byte_counts [i] = 0;
+       while (pinned_objects) {
+               ObjectList *next = pinned_objects->next;
+               free_internal_mem (pinned_objects, INTERNAL_MEM_STATISTICS);
+               pinned_objects = next;
+       }
 }
 
 static void
@@ -88,5 +124,9 @@ static void
 pin_stats_register_object (char *obj, size_t size)
 {
        int pin_types = 0;
+       ObjectList *list = get_internal_mem (sizeof (ObjectList), INTERNAL_MEM_STATISTICS);
        pin_stats_count_object_from_tree (obj, size, pin_stat_addresses, &pin_types);
+       list->obj = (MonoObject*)obj;
+       list->next = pinned_objects;
+       pinned_objects = list;
 }