#define BITMAP_EL_SIZE (sizeof (gsize) * 8)
static gsize*
-compute_class_bitmap (MonoClass *class, gsize *bitmap, int size, int offset, int *max_set)
+compute_class_bitmap (MonoClass *class, gsize *bitmap, int size, int offset, int *max_set, gboolean static_fields)
{
MonoClassField *field;
MonoClass *p;
guint32 pos;
- int max_size = class->instance_size / sizeof (gpointer);
+ int max_size;
+
+ if (static_fields)
+ max_size = class->class_size / sizeof (gpointer);
+ else
+ max_size = class->instance_size / sizeof (gpointer);
if (max_size > size) {
bitmap = g_malloc0 (sizeof (gsize) * ((max_size) + 1));
}
while ((field = mono_class_get_fields (p, &iter))) {
MonoType *type;
- if (field->type->attrs & (FIELD_ATTRIBUTE_STATIC | FIELD_ATTRIBUTE_HAS_FIELD_RVA))
- continue;
+ if (static_fields) {
+ if (!(field->type->attrs & (FIELD_ATTRIBUTE_STATIC | FIELD_ATTRIBUTE_HAS_FIELD_RVA)))
+ continue;
+ } else {
+ if (field->type->attrs & (FIELD_ATTRIBUTE_STATIC | FIELD_ATTRIBUTE_HAS_FIELD_RVA))
+ continue;
+ }
/* FIXME: should not happen, flag as type load error */
if (field->type->byref)
break;
case MONO_TYPE_U:
case MONO_TYPE_PTR:
case MONO_TYPE_FNPTR:
+#ifdef HAVE_SGEN_GC
+ break;
+#endif
case MONO_TYPE_STRING:
case MONO_TYPE_SZARRAY:
case MONO_TYPE_CLASS:
MonoClass *fclass = mono_class_from_mono_type (field->type);
if (fclass->has_references) {
/* remove the object header */
- compute_class_bitmap (fclass, bitmap, size, pos - (sizeof (MonoObject) / sizeof (gpointer)), max_set);
+ compute_class_bitmap (fclass, bitmap, size, pos - (sizeof (MonoObject) / sizeof (gpointer)), max_set, FALSE);
}
break;
}
break;
}
}
+ if (static_fields)
+ break;
}
return bitmap;
}
class->name_space, class->name);*/
} else {
/* remove the object header */
- bitmap = compute_class_bitmap (class->element_class, default_bitmap, sizeof (default_bitmap) * 8, - (sizeof (MonoObject) / sizeof (gpointer)), &max_set);
+ bitmap = compute_class_bitmap (class->element_class, default_bitmap, sizeof (default_bitmap) * 8, - (sizeof (MonoObject) / sizeof (gpointer)), &max_set, FALSE);
class->gc_descr = mono_gc_make_descr_for_array (TRUE, bitmap, mono_array_element_size (class) / sizeof (gpointer), mono_array_element_size (class));
/*printf ("new vt array descriptor: 0x%x for %s.%s\n", class->gc_descr,
class->name_space, class->name);*/
/*static int count = 0;
if (count++ > 58)
return;*/
- bitmap = compute_class_bitmap (class, default_bitmap, sizeof (default_bitmap) * 8, 0, &max_set);
+ bitmap = compute_class_bitmap (class, default_bitmap, sizeof (default_bitmap) * 8, 0, &max_set, FALSE);
#ifdef HAVE_BOEHM_GC
/* It seems there are issues when the bitmap doesn't fit: play it safe */
if (max_set >= 30) {
return runtime_info->domain_vtables [domain->domain_id];
}
if (!class->inited)
- mono_class_init (class);
+ if (!mono_class_init (class)){
+ MonoException *exc;
+ mono_domain_unlock (domain);
+ exc = mono_class_get_exception_for_failure (class);
+ g_assert (exc);
+ mono_raise_exception (exc);
+ }
mono_class_setup_vtable (class);
if (class->class_size) {
if (class->has_static_refs) {
- vt->data = mono_gc_alloc_fixed (class->class_size, NULL);
+ gpointer statics_gc_descr;
+ int max_set = 0;
+ gsize default_bitmap [4] = {0};
+ gsize *bitmap;
+
+ bitmap = compute_class_bitmap (class, default_bitmap, sizeof (default_bitmap) * 8, 0, &max_set, TRUE);
+ /*g_print ("bitmap 0x%x for %s.%s (size: %d)\n", bitmap [0], class->name_space, class->name, class->class_size);*/
+ statics_gc_descr = mono_gc_make_descr_from_bitmap (bitmap, max_set? max_set + 1: 0);
+ vt->data = mono_gc_alloc_fixed (class->class_size, statics_gc_descr);
mono_domain_add_class_static_data (domain, class, vt->data, NULL);
+ if (bitmap != default_bitmap)
+ g_free (bitmap);
} else {
vt->data = mono_mempool_alloc0 (domain->mp, class->class_size);
}
return key;
}
+/**
+ * copy_remote_class_key:
+ *
+ * Make a copy of KEY in the mempool MP and return the copy.
+ */
+static gpointer*
+copy_remote_class_key (MonoMemPool *mp, gpointer *key)
+{
+ int key_size = (GPOINTER_TO_UINT (key [0]) + 1) * sizeof (gpointer);
+ gpointer *mp_key = mono_mempool_alloc (mp, key_size);
+
+ memcpy (mp_key, key, key_size);
+
+ return mp_key;
+}
+
/**
* mono_remote_class:
* @domain: the application domain
mono_remote_class (MonoDomain *domain, MonoString *class_name, MonoClass *proxy_class)
{
MonoRemoteClass *rc;
- gpointer* key;
+ gpointer* key, *mp_key;
key = create_remote_class_key (NULL, proxy_class);
return rc;
}
+ mp_key = copy_remote_class_key (domain->mp, key);
+ g_free (key);
+ key = mp_key;
+
if (proxy_class->flags & TYPE_ATTRIBUTE_INTERFACE) {
rc = mono_mempool_alloc (domain->mp, sizeof(MonoRemoteClass) + sizeof(MonoClass*));
rc->interface_count = 1;
rc->default_vtable = NULL;
rc->xdomain_vtable = NULL;
- rc->proxy_class_name = mono_string_to_utf8 (class_name);
+ rc->proxy_class_name = mono_string_to_utf8_mp (domain->mp, class_name);
g_hash_table_insert (domain->proxy_vtable_hash, key, rc);
clone_remote_class (MonoDomain *domain, MonoRemoteClass* remote_class, MonoClass *extra_class)
{
MonoRemoteClass *rc;
- gpointer* key;
+ gpointer* key, *mp_key;
key = create_remote_class_key (remote_class, extra_class);
rc = g_hash_table_lookup (domain->proxy_vtable_hash, key);
return rc;
}
+ mp_key = copy_remote_class_key (domain->mp, key);
+ g_free (key);
+ key = mp_key;
+
if (extra_class->flags & TYPE_ATTRIBUTE_INTERFACE) {
int i,j;
rc = mono_mempool_alloc (domain->mp, sizeof(MonoRemoteClass) + sizeof(MonoClass*) * (remote_class->interface_count + 1));
case MONO_TYPE_CLASS:
case MONO_TYPE_OBJECT:
case MONO_TYPE_ARRAY:
+ mono_gc_wbarrier_generic_store (dest, deref_pointer? *(gpointer*)value: value);
+ return;
+ case MONO_TYPE_FNPTR:
case MONO_TYPE_PTR: {
gpointer *p = (gpointer*)dest;
*p = deref_pointer? *(gpointer*)value: value;
/*
* mono_nullable_init:
+ * @buf: The nullable structure to initialize.
+ * @value: the value to initialize from
+ * @klass: the type for the object
*
- * Initialize the nullable structure pointed to by @buf from @value which
- * should be a boxed value type. Since Nullables have variable structure, we
- * can't define a C structure for them.
+ * Initialize the nullable structure pointed to by @buf from @value which
+ * should be a boxed value type. The size of @buf should be able to hold
+ * as much data as the @klass->instance_size (which is the number of bytes
+ * that will be copies).
+ *
+ * Since Nullables have variable structure, we can not define a C
+ * structure for them.
*/
void
mono_nullable_init (guint8 *buf, MonoObject *value, MonoClass *klass)
/**
* mono_nullable_box:
+ * @buf: The buffer representing the data to be boxed
+ * @klass: the type to box it as.
*
- * Creates a boxed vtype or NULL from the Nullable structure pointed to by
+ * Creates a boxed vtype or NULL from the Nullable structure pointed to by
* @buf.
*/
MonoObject*
gchar *utf8_fullpath;
int result;
+ g_assert (method != NULL);
+
mono_thread_set_main (mono_thread_current ());
main_args = g_new0 (char*, argc);
mono_value_copy (gpointer dest, gpointer src, MonoClass *klass)
{
int size = mono_class_value_size (klass, NULL);
+ mono_gc_wbarrier_value_copy (dest, src, 1, klass);
memcpy (dest, src, size);
}
{
int size = mono_array_element_size (dest->obj.vtable->klass);
char *d = mono_array_addr_with_size (dest, size, dest_idx);
+ mono_gc_wbarrier_value_copy (d, src, count, mono_object_class (dest)->element_class);
memmove (d, src, size * count);
}
mono_object_get_size (MonoObject* o)
{
MonoClass* klass = mono_object_class (o);
-
- if (klass == mono_defaults.string_class)
+ if (klass == mono_defaults.string_class) {
return sizeof (MonoString) + 2 * mono_string_length ((MonoString*) o) + 2;
- else if (klass->parent == mono_defaults.array_class)
- return sizeof (MonoArray) + mono_array_element_size (klass) * mono_array_length ((MonoArray*) o);
- else
+ } else if (o->vtable->rank) {
+ MonoArray *array = (MonoArray*)o;
+ size_t size = sizeof (MonoArray) + mono_array_element_size (klass) * mono_array_length (array);
+ if (array->bounds) {
+ size += 3;
+ size &= ~3;
+ size += sizeof (MonoArrayBounds) * o->vtable->rank;
+ }
+ return size;
+ } else {
return mono_class_instance_size (klass);
+ }
}
/**
info->res = mono_g_hash_table_lookup (domain->ldstr_table, info->ins);
}
+#ifdef HAVE_SGEN_GC
+
+static MonoString*
+mono_string_get_pinned (MonoString *str)
+{
+ int size;
+ MonoString *news;
+ size = sizeof (MonoString) + 2 * (mono_string_length (str) + 1);
+ news = mono_gc_alloc_pinned_obj (((MonoObject*)str)->vtable, size);
+ memcpy (mono_string_chars (news), mono_string_chars (str), mono_string_length (str) * 2);
+ news->length = mono_string_length (str);
+ return news;
+}
+
+#else
+#define mono_string_get_pinned(str) (str)
+#endif
+
static MonoString*
mono_string_is_interned_lookup (MonoString *str, int insert)
{
return res;
}
if (insert) {
+ str = mono_string_get_pinned (str);
mono_g_hash_table_insert (ldstr_table, str, str);
ldstr_unlock ();
return str;
return interned;
}
+ o = mono_string_get_pinned (o);
mono_g_hash_table_insert (domain->ldstr_table, o, o);
ldstr_unlock ();
return mono_string_new_utf16 (domain, data, len);
}
+/**
+ * mono_string_to_utf8_mp:
+ * @s: a System.String
+ *
+ * Same as mono_string_to_utf8, but allocate the string from a mempool.
+ */
+char *
+mono_string_to_utf8_mp (MonoMemPool *mp, MonoString *s)
+{
+ char *r = mono_string_to_utf8 (s);
+ char *mp_s;
+ int len;
+
+ if (!r)
+ return NULL;
+
+ len = strlen (r) + 1;
+ mp_s = mono_mempool_alloc (mp, len);
+ memcpy (mp_s, r, len);
+
+ g_free (r);
+
+ return mp_s;
+}
+
static void
default_ex_handler (MonoException *ex)
{
*
*/
MonoAsyncResult *
-mono_async_result_new (MonoDomain *domain, HANDLE handle, MonoObject *state, gpointer data)
+mono_async_result_new (MonoDomain *domain, HANDLE handle, MonoObject *state, gpointer data, MonoObject *object_data)
{
MonoAsyncResult *res = (MonoAsyncResult *)mono_object_new (domain, mono_defaults.asyncresult_class);
MonoMethod *method = mono_get_context_capture_method ();
}
res->data = data;
+ MONO_OBJECT_SETREF (res, object_data, object_data);
MONO_OBJECT_SETREF (res, async_state, state);
if (handle != NULL)
MONO_OBJECT_SETREF (res, handle, (MonoObject *) mono_wait_handle_new (domain, handle));
MonoMethodMessage *msg;
MonoArray *out_args;
MonoObject *exc;
- gpointer tmp;
+ char* full_name;
g_assert (this->vtable->klass == mono_defaults.transparent_proxy_class);
-
- if (!res)
- res = &tmp;
+ g_assert (res != NULL);
if (tp->remote_class->proxy_class->contextbound && tp->rp->context == (MonoObject *) mono_context_get ()) {
mono_field_get_value (tp->rp->unwrapped_server, field, res);
out_args = mono_array_new (domain, mono_defaults.object_class, 1);
mono_message_init (domain, msg, mono_method_get_object (domain, getter, NULL), out_args);
- mono_array_setref (msg->args, 0, mono_string_new (domain, klass->name));
+ full_name = mono_type_get_full_name (klass);
+ mono_array_setref (msg->args, 0, mono_string_new (domain, full_name));
mono_array_setref (msg->args, 1, mono_string_new (domain, field->name));
+ g_free (full_name);
mono_remoting_invoke ((MonoObject *)(tp->rp), msg, &exc, &out_args);
MonoMethodMessage *msg;
MonoArray *out_args;
MonoObject *exc, *res;
+ char* full_name;
g_assert (this->vtable->klass == mono_defaults.transparent_proxy_class);
mono_message_init (domain, msg, mono_method_get_object (domain, getter, NULL), out_args);
- mono_array_setref (msg->args, 0, mono_string_new (domain, klass->name));
+ full_name = mono_type_get_full_name (klass);
+ mono_array_setref (msg->args, 0, mono_string_new (domain, full_name));
mono_array_setref (msg->args, 1, mono_string_new (domain, field->name));
+ g_free (full_name);
mono_remoting_invoke ((MonoObject *)(tp->rp), msg, &exc, &out_args);
MonoArray *out_args;
MonoObject *exc;
MonoObject *arg;
+ char* full_name;
g_assert (this->vtable->klass == mono_defaults.transparent_proxy_class);
msg = (MonoMethodMessage *)mono_object_new (domain, mono_defaults.mono_method_message_class);
mono_message_init (domain, msg, mono_method_get_object (domain, setter, NULL), NULL);
- mono_array_setref (msg->args, 0, mono_string_new (domain, klass->name));
+ full_name = mono_type_get_full_name (klass);
+ mono_array_setref (msg->args, 0, mono_string_new (domain, full_name));
mono_array_setref (msg->args, 1, mono_string_new (domain, field->name));
mono_array_setref (msg->args, 2, arg);
+ g_free (full_name);
mono_remoting_invoke ((MonoObject *)(tp->rp), msg, &exc, &out_args);
MonoMethodMessage *msg;
MonoArray *out_args;
MonoObject *exc;
+ char* full_name;
g_assert (this->vtable->klass == mono_defaults.transparent_proxy_class);
msg = (MonoMethodMessage *)mono_object_new (domain, mono_defaults.mono_method_message_class);
mono_message_init (domain, msg, mono_method_get_object (domain, setter, NULL), NULL);
- mono_array_setref (msg->args, 0, mono_string_new (domain, klass->name));
+ full_name = mono_type_get_full_name (klass);
+ mono_array_setref (msg->args, 0, mono_string_new (domain, full_name));
mono_array_setref (msg->args, 1, mono_string_new (domain, field->name));
mono_array_setref (msg->args, 2, arg);
+ g_free (full_name);
mono_remoting_invoke ((MonoObject *)(tp->rp), msg, &exc, &out_args);