2 * Copyright 2016 Microsoft
3 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
5 #ifndef __MONO_METADATA_REFLECTION_CACHE_H__
6 #define __MONO_METADATA_REFLECTION_CACHE_H__
9 #include <mono/metadata/domain-internals.h>
10 #include <mono/metadata/mono-hash.h>
11 #include <mono/metadata/mempool.h>
14 * We need to return always the same object for MethodInfo, FieldInfo etc..
15 * but we need to consider the reflected type.
16 * type uses a different hash, since it uses custom hash/equal functions.
25 reflected_equal (gconstpointer a, gconstpointer b);
28 reflected_hash (gconstpointer a);
31 /* ReflectedEntry doesn't need to be GC tracked */
32 #define ALLOC_REFENTRY g_new0 (ReflectedEntry, 1)
33 #define FREE_REFENTRY(entry) g_free ((entry))
34 #define REFENTRY_REQUIRES_CLEANUP
36 #define ALLOC_REFENTRY (ReflectedEntry *)mono_mempool_alloc (domain->mp, sizeof (ReflectedEntry))
38 #define FREE_REFENTRY(entry)
42 #define CACHE_OBJECT(t,p,o,k) \
48 mono_domain_lock (domain); \
49 if (!domain->refobject_hash) \
50 domain->refobject_hash = mono_g_hash_table_new_type (reflected_hash, reflected_equal, MONO_HASH_VALUE_GC, MONO_ROOT_SOURCE_DOMAIN, "domain reflection objects table"); \
51 _obj = (t)mono_g_hash_table_lookup (domain->refobject_hash, &pe); \
53 ReflectedEntry *e = ALLOC_REFENTRY; \
56 mono_g_hash_table_insert (domain->refobject_hash, e,o); \
59 mono_domain_unlock (domain); \
63 #define CHECK_OBJECT(t,p,k) \
69 mono_domain_lock (domain); \
70 if (!domain->refobject_hash) \
71 domain->refobject_hash = mono_g_hash_table_new_type (reflected_hash, reflected_equal, MONO_HASH_VALUE_GC, MONO_ROOT_SOURCE_DOMAIN, "domain reflection objects table"); \
72 if ((_obj = (t)mono_g_hash_table_lookup (domain->refobject_hash, &e))) { \
73 mono_domain_unlock (domain); \
76 mono_domain_unlock (domain); \
80 #endif /*__MONO_METADATA_REFLECTION_CACHE_H__*/