2 * gc-internal-agnostic.h: Mono-agnostic GC interface.
4 * Copyright (C) 2015 Xamarin Inc
6 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
9 #ifndef __MONO_METADATA_GCINTERNALAGNOSTIC_H__
10 #define __MONO_METADATA_GCINTERNALAGNOSTIC_H__
16 #include "mono/utils/mono-compiler.h"
17 #include "mono/utils/parse.h"
18 #include "mono/utils/memfuncs.h"
20 #include "mono/sgen/sgen-conf.h"
23 /* h indicates whether to hide or just tag.
24 * (-!!h ^ p) is used instead of (h ? ~p : p) to avoid multiple mentions of p.
26 #define MONO_GC_HIDE_POINTER(p,t,h) ((gpointer)(((-(size_t)!!(h) ^ (size_t)(p)) & ~(size_t)3) | ((t) & (size_t)3)))
27 #define MONO_GC_REVEAL_POINTER(p,h) ((gpointer)((-(size_t)!!(h) ^ (size_t)(p)) & ~(size_t)3))
29 #define MONO_GC_POINTER_TAG(p) ((size_t)(p) & (size_t)3)
31 #define MONO_GC_HANDLE_OCCUPIED_MASK (1)
32 #define MONO_GC_HANDLE_VALID_MASK (2)
33 #define MONO_GC_HANDLE_TAG_MASK (MONO_GC_HANDLE_OCCUPIED_MASK | MONO_GC_HANDLE_VALID_MASK)
35 #define MONO_GC_HANDLE_METADATA_POINTER(p,h) (MONO_GC_HIDE_POINTER ((p), MONO_GC_HANDLE_OCCUPIED_MASK, (h)))
36 #define MONO_GC_HANDLE_OBJECT_POINTER(p,h) (MONO_GC_HIDE_POINTER ((p), MONO_GC_HANDLE_OCCUPIED_MASK | MONO_GC_HANDLE_VALID_MASK, (h)))
38 #define MONO_GC_HANDLE_OCCUPIED(slot) ((size_t)(slot) & MONO_GC_HANDLE_OCCUPIED_MASK)
39 #define MONO_GC_HANDLE_VALID(slot) ((size_t)(slot) & MONO_GC_HANDLE_VALID_MASK)
41 #define MONO_GC_HANDLE_TAG(slot) ((size_t)(slot) & MONO_GC_HANDLE_TAG_MASK)
43 #define MONO_GC_HANDLE_IS_OBJECT_POINTER(slot) (MONO_GC_HANDLE_TAG (slot) == (MONO_GC_HANDLE_OCCUPIED_MASK | MONO_GC_HANDLE_VALID_MASK))
44 #define MONO_GC_HANDLE_IS_METADATA_POINTER(slot) (MONO_GC_HANDLE_TAG (slot) == MONO_GC_HANDLE_OCCUPIED_MASK)
48 HANDLE_WEAK
= HANDLE_TYPE_MIN
,
55 #define GC_HANDLE_TYPE_IS_WEAK(x) ((x) <= HANDLE_WEAK_TRACK)
57 #define MONO_GC_HANDLE_TYPE_SHIFT (3)
58 #define MONO_GC_HANDLE_TYPE_MASK ((1 << MONO_GC_HANDLE_TYPE_SHIFT) - 1)
59 #define MONO_GC_HANDLE_TYPE(x) ((GCHandleType)(((x) & MONO_GC_HANDLE_TYPE_MASK) - 1))
60 #define MONO_GC_HANDLE_SLOT(x) ((x) >> MONO_GC_HANDLE_TYPE_SHIFT)
61 #define MONO_GC_HANDLE_TYPE_IS_WEAK(x) ((x) <= HANDLE_WEAK_TRACK)
62 #define MONO_GC_HANDLE(slot, type) (((slot) << MONO_GC_HANDLE_TYPE_SHIFT) | (((type) & MONO_GC_HANDLE_TYPE_MASK) + 1))
67 guint64 minor_gc_time
;
68 guint64 major_gc_time
;
69 guint64 major_gc_time_concurrent
;
72 extern GCStats gc_stats
;
75 typedef SgenDescriptor MonoGCDescriptor
;
76 #define MONO_GC_DESCRIPTOR_NULL SGEN_DESCRIPTOR_NULL
78 typedef void* MonoGCDescriptor
;
79 #define MONO_GC_DESCRIPTOR_NULL NULL
83 * Try to register a foreign thread with the GC, if we fail or the backend
84 * can't cope with this concept - we return FALSE.
86 extern gboolean
mono_gc_register_thread (void *baseptr
);
88 gboolean
mono_gc_parse_environment_string_extract_number (const char *str
, size_t *out
);
90 MonoGCDescriptor
mono_gc_make_descr_for_object (gsize
*bitmap
, int numbits
, size_t obj_size
);
91 MonoGCDescriptor
mono_gc_make_descr_for_array (int vector
, gsize
*elem_bitmap
, int numbits
, size_t elem_size
);
93 /* simple interface for data structures needed in the runtime */
94 MonoGCDescriptor
mono_gc_make_descr_from_bitmap (gsize
*bitmap
, int numbits
);
96 /* Return a root descriptor for a root with all refs */
97 MonoGCDescriptor
mono_gc_make_root_descr_all_refs (int numbits
);
99 /* Return the bitmap encoded by a descriptor */
100 gsize
* mono_gc_get_bitmap_for_descr (MonoGCDescriptor descr
, int *numbits
);
103 These functions must be used when it's possible that either destination is not
104 word aligned or size is not a multiple of word size.
106 void mono_gc_bzero_atomic (void *dest
, size_t size
);
107 void mono_gc_bzero_aligned (void *dest
, size_t size
);
108 void mono_gc_memmove_atomic (void *dest
, const void *src
, size_t size
);
109 void mono_gc_memmove_aligned (void *dest
, const void *src
, size_t size
);
111 FILE *mono_gc_get_logfile (void);
113 /* equivalent to options set via MONO_GC_PARAMS */
114 void mono_gc_params_set (const char* options
);
115 /* equivalent to options set via MONO_GC_DEBUG */
116 void mono_gc_debug_set (const char* options
);