/* Enable perf jit dump support */
#cmakedefine ENABLE_JIT_DUMP 1
+/* Enable System.WeakAttribute support */
+#cmakedefine ENABLE_WEAK_ATTR 1
+
#if defined(ENABLE_LLVM) && defined(HOST_WIN32) && defined(TARGET_WIN32) && (!defined(TARGET_AMD64) || !defined(_MSC_VER))
#error LLVM for host=Windows and target=Windows is only supported on x64 MSVC build.
#endif
// - Disallow on structs/static fields/nonref fields
gboolean has_weak_fields = FALSE;
+#ifdef ENABLE_WEAK_ATTR
if (mono_class_has_static_metadata (klass)) {
for (MonoClass *p = klass; p != NULL; p = p->parent) {
gpointer iter = NULL;
}
}
}
+#endif
/*
* Check that any fields of IsByRefLike type are instance
metadata_foreach_custom_attr_from_index (image, idx, func, user_data);
}
+#ifdef ENABLE_WEAK_ATTR
static void
init_weak_fields_inner (MonoImage *image, GHashTable *indexes)
{
}
}
}
+#endif
/*
* mono_assembly_init_weak_fields:
void
mono_assembly_init_weak_fields (MonoImage *image)
{
+#ifdef ENABLE_WEAK_ATTR
if (image->weak_fields_inited)
return;
g_hash_table_destroy (indexes);
}
mono_image_unlock (image);
+#endif
}
/*
gboolean
mono_assembly_is_weak_field (MonoImage *image, guint32 field_idx)
{
+#ifdef ENABLE_WEAK_ATTR
if (image->dynamic)
return FALSE;
/* The hash is not mutated, no need to lock */
return g_hash_table_lookup (image->weak_field_indexes, GINT_TO_POINTER (field_idx)) != NULL;
+#else
+ g_assert_not_reached ();
+#endif
}
free_hash (image->wrapper_param_names);
free_hash (image->native_func_wrapper_cache);
mono_conc_hashtable_destroy (image->typespec_cache);
+#ifdef ENABLE_WEAK_ATTR
free_hash (image->weak_field_indexes);
+#endif
mono_wrapper_caches_free (&image->wrapper_caches);
MonoGenericContainer *anonymous_generic_class_container;
MonoGenericContainer *anonymous_generic_method_container;
+#ifdef ENABLE_WEAK_ATTR
gboolean weak_fields_inited;
/* Contains 1 based indexes */
GHashTable *weak_field_indexes;
+#endif
/* baseline images only: whether any metadata updates have been applied to this image */
gboolean has_updates;
*/
/*printf ("new descriptor: %p 0x%x for %s.%s\n", class->gc_descr, bitmap [0], class->name_space, class->name);*/
+#ifdef ENABLE_WEAK_ATTR
if (m_class_has_weak_fields (klass)) {
gsize *weak_bitmap = NULL;
int weak_bitmap_nbits = 0;
mono_class_set_weak_bitmap (klass, weak_bitmap_nbits, weak_bitmap);
mono_loader_unlock ();
}
+#endif
gc_descr = mono_gc_make_descr_for_object (bitmap, max_set + 1, m_class_get_instance_size (klass));
}
if (G_UNLIKELY (m_class_has_finalize (klass)))
mono_object_register_finalizer (o);
+#ifdef ENABLE_WEAK_ATTR
if (G_UNLIKELY (m_class_has_weak_fields (klass)))
mono_gc_register_obj_with_weak_fields (o);
+#endif
return o;
}
if (G_UNLIKELY (m_class_has_finalize (klass)))
mono_object_register_finalizer_handle (o);
+#ifdef ENABLE_WEAK_ATTR
if (G_UNLIKELY (m_class_has_weak_fields (klass)))
mono_gc_register_object_with_weak_fields (o);
+#endif
return o;
}
static void
emit_weak_field_indexes (MonoAotCompile *acfg)
{
+#ifdef ENABLE_WEAK_ATTR
GHashTable *indexes;
GHashTableIter iter;
gpointer key, value;
emit_aot_data (acfg, MONO_AOT_TABLE_WEAK_FIELD_INDEXES, "weak_field_indexes", buf, p - buf);
g_free (buf);
+#else
+ guint8 buf [4];
+ guint8 *p = &buf[0];
+
+ encode_int (0, p, &p);
+ emit_aot_data (acfg, MONO_AOT_TABLE_WEAK_FIELD_INDEXES, "weak_field_indexes", buf, p - buf);
+#endif
}
static void
if (!amodule)
return NULL;
+#if ENABLE_WEAK_ATTR
/* Initialize weak field indexes from the cached copy */
guint32 *indexes = (guint32*)amodule->weak_field_indexes;
int len = indexes [0];
for (int i = 0; i < len; ++i)
g_hash_table_insert (indexes_hash, GUINT_TO_POINTER (indexes [i + 1]), GUINT_TO_POINTER (1));
return indexes_hash;
+#else
+ g_assert_not_reached ();
+#endif
}
/* Compute the boundaries of the LLVM code for AMODULE. */
callbacks.get_ftnptr = get_ftnptr_for_method;
#endif
callbacks.is_interpreter_enabled = mini_is_interpreter_enabled;
+#if ENABLE_WEAK_ATTR
callbacks.get_weak_field_indexes = mono_aot_get_weak_field_indexes;
+#endif
callbacks.metadata_update_published = mini_invalidate_transformed_interp_methods;
callbacks.interp_jit_info_foreach = mini_interp_jit_info_foreach;