Add [Category ("NotWorking")] to failing test.
[mono.git] / mono / metadata / sgen-copy-object.h
1 /*
2  * sgen-copy-object.h: This is where objects are copied.
3  *
4  * Copyright 2001-2003 Ximian, Inc
5  * Copyright 2003-2010 Novell, Inc.
6  * Copyright (C) 2012 Xamarin Inc
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License 2.0 as published by the Free Software Foundation;
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License 2.0 along with this library; if not, write to the Free
19  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21 extern long long stat_copy_object_called_nursery;
22 extern long long stat_objects_copied_nursery;
23
24 extern long long stat_nursery_copy_object_failed_from_space;
25 extern long long stat_nursery_copy_object_failed_forwarded;
26 extern long long stat_nursery_copy_object_failed_pinned;
27
28 extern long long stat_slots_allocated_in_vain;
29
30 /*
31  * This function can be used even if the vtable of obj is not valid
32  * anymore, which is the case in the parallel collector.
33  */
34 static inline void
35 par_copy_object_no_checks (char *destination, MonoVTable *vt, void *obj, mword objsize, SgenGrayQueue *queue)
36 {
37 #ifdef __GNUC__
38         static const void *copy_labels [] = { &&LAB_0, &&LAB_1, &&LAB_2, &&LAB_3, &&LAB_4, &&LAB_5, &&LAB_6, &&LAB_7, &&LAB_8 };
39 #endif
40
41         SGEN_ASSERT (9, vt->klass->inited, "vtable %p for class %s:%s was not initialized", vt, vt->klass->name_space, vt->klass->name);
42         SGEN_LOG (9, " (to %p, %s size: %lu)", destination, ((MonoObject*)obj)->vtable->klass->name, (unsigned long)objsize);
43         binary_protocol_copy (obj, destination, vt, objsize);
44
45 #ifdef ENABLE_DTRACE
46         if (G_UNLIKELY (MONO_GC_OBJ_MOVED_ENABLED ())) {
47                 int dest_gen = sgen_ptr_in_nursery (destination) ? GENERATION_NURSERY : GENERATION_OLD;
48                 int src_gen = sgen_ptr_in_nursery (obj) ? GENERATION_NURSERY : GENERATION_OLD;
49                 MONO_GC_OBJ_MOVED ((mword)destination, (mword)obj, dest_gen, src_gen, objsize, vt->klass->name_space, vt->klass->name);
50         }
51 #endif
52
53 #ifdef __GNUC__
54         if (objsize <= sizeof (gpointer) * 8) {
55                 mword *dest = (mword*)destination;
56                 goto *copy_labels [objsize / sizeof (gpointer)];
57         LAB_8:
58                 (dest) [7] = ((mword*)obj) [7];
59         LAB_7:
60                 (dest) [6] = ((mword*)obj) [6];
61         LAB_6:
62                 (dest) [5] = ((mword*)obj) [5];
63         LAB_5:
64                 (dest) [4] = ((mword*)obj) [4];
65         LAB_4:
66                 (dest) [3] = ((mword*)obj) [3];
67         LAB_3:
68                 (dest) [2] = ((mword*)obj) [2];
69         LAB_2:
70                 (dest) [1] = ((mword*)obj) [1];
71         LAB_1:
72                 ;
73         LAB_0:
74                 ;
75         } else {
76                 /*can't trust memcpy doing word copies */
77                 mono_gc_memmove (destination + sizeof (mword), (char*)obj + sizeof (mword), objsize - sizeof (mword));
78         }
79 #else
80                 mono_gc_memmove (destination + sizeof (mword), (char*)obj + sizeof (mword), objsize - sizeof (mword));
81 #endif
82         /* adjust array->bounds */
83         SGEN_ASSERT (9, vt->gc_descr, "vtable %p for class %s:%s has no gc descriptor", vt, vt->klass->name_space, vt->klass->name);
84
85         if (G_UNLIKELY (vt->rank && ((MonoArray*)obj)->bounds)) {
86                 MonoArray *array = (MonoArray*)destination;
87                 array->bounds = (MonoArrayBounds*)((char*)destination + ((char*)((MonoArray*)obj)->bounds - (char*)obj));
88                 SGEN_LOG (9, "Array instance %p: size: %lu, rank: %d, length: %lu", array, (unsigned long)objsize, vt->rank, (unsigned long)mono_array_length (array));
89         }
90         if (G_UNLIKELY (mono_profiler_events & MONO_PROFILE_GC_MOVES))
91                 sgen_register_moved_object (obj, destination);
92         obj = destination;
93         if (queue) {
94                 SGEN_LOG (9, "Enqueuing gray object %p (%s)", obj, sgen_safe_name (obj));
95                 GRAY_OBJECT_ENQUEUE (queue, obj);
96         }
97 }
98
99 /*
100  * This can return OBJ itself on OOM.
101  */
102 #ifdef _MSC_VER
103 static __declspec(noinline) void*
104 #else
105 static G_GNUC_UNUSED void* __attribute__((noinline))
106 #endif
107 copy_object_no_checks (void *obj, SgenGrayQueue *queue)
108 {
109         MonoVTable *vt = ((MonoObject*)obj)->vtable;
110         gboolean has_references = SGEN_VTABLE_HAS_REFERENCES (vt);
111         mword objsize = SGEN_ALIGN_UP (sgen_par_object_get_size (vt, (MonoObject*)obj));
112         char *destination = COLLECTOR_SERIAL_ALLOC_FOR_PROMOTION (vt, obj, objsize, has_references);
113
114         if (G_UNLIKELY (!destination)) {
115                 collector_pin_object (obj, queue);
116                 sgen_set_pinned_from_failed_allocation (objsize);
117                 return obj;
118         }
119
120         par_copy_object_no_checks (destination, vt, obj, objsize, has_references ? queue : NULL);
121         /* FIXME: mark mod union cards if necessary */
122
123         /* set the forwarding pointer */
124         SGEN_FORWARD_OBJECT (obj, destination);
125
126         return destination;
127 }