[Mono-dev] Runtime.MonoIline

Jerry Maine crashfourit at gmail.com
Sat Jan 24 15:00:09 EST 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Rodrigo Kumpera wrote:
> No, I spend to whole week fixing race conditions and been sick.
> The code is pretty simple, thou:
>
> /*NOTE, this doesn't work with dynamic assemblies*/
> void
> mono_image_has_assembly_ref (MonoImage *image, const char
> *target_assembly)
>         MonoTableInfo *t;
>         int i;
>         if (image->dynamic)
>             return FALSE;
>         t =  = &image->tables [MONO_TABLE_ASSEMBLYREF];
>         for (i = 0; i < t->rows; i++) {
>             const char *ref_name = mono_metadata_string_heap
> (mono_metadata_decode_row_col (t, i, MONO_ASSEMBLYREF_NAME))
>             if (!strcmp (target_assembly, ref_name))
>                 return TRUE;
>         }
>         return FALSE;
> }
>
>
> The part that checks for the presence of the attribute I didn't work
> much, but it's a trimmed down version of
> reflection.c mono_custom_attrs_from_index
>
>
>
> On Fri, Jan 23, 2009 at 7:39 PM, Jerry Maine <crashfourit at gmail.com
> <mailto:crashfourit at gmail.com>> wrote:
>
>     Kumpera, have you finished your patch that would make my inlining
>     patch simpler?
>
>     _______________________________________________
>     Mono-devel-list mailing list
>     Mono-devel-list at lists.ximian.com
>     <mailto:Mono-devel-list at lists.ximian.com>
>     http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>
This is the idea, most cases we won't find the assembly reference in
the image and it will speed up those cases. Then we can add those
optimizations you here talking about to test if the attribute is
present in small increments over time.

/*NOTE, this doesn't work with dynamic assemblies*/
gboolean
mono_image_has_assembly_ref (MonoImage *image, const char
*target_assembly)
{
    MonoTableInfo *t;
    int i;
 
    //TODO: make this work with dynamic assemblies.
    if (image->dynamic)
        return FALSE;

    t = &image->tables [MONO_TABLE_ASSEMBLYREF];
        for (i = 0; i < t->rows; i++) {
        const char *ref_name = mono_metadata_string_heap
(mono_metadata_decode_row_col (t, i, MONO_ASSEMBLYREF_NAME))
        if (!strcmp (target_assembly, ref_name))
        return TRUE;
    }
    return FALSE;
}


gboolean
mono_assembly_has_custom_attr_partial (MonoAssembly *assembly, const
char *attr_assembly, const char *attr_namespace, const char *attr)
{
    MonoCustomAttrInfo *attributes;

    if (attr_assembly != NULL)
        if (!mono_image_has_assembly_ref(assembly->image, attr_assembly)
            return FALSE;

    attributes = mono_custom_attrs_from_assembly(assembly);

    if (attributes) {
        for (i = 0; i < attributes->num_attrs; ++i) {
            MonoClass *klass = attributes->attrs [i].ctor->klass;
            if (strcmp (klass->image->assembly_name, attr_assembly) ==
0) {
                if (strcmp (klass->name_space, attr_namespace) == 0)
                    if (strcmp (klass->name, attr) == 0)
                        return TRUE;
            }
        }
        mono_custom_attrs_free (attributes); 
    }

    return FALSE;
}

gboolean
mono_method_has_custom_attr_partial (MonoMethod *method, const char
*attr_assembly, const char *attr_namespace, const char *attr)
{
    MonoCustomAttrInfo *attributes;

    if (attr_assembly != NULL)
        if (!mono_image_has_assembly_ref(method->klass->image,
attr_assembly)
            return FALSE;

    attributes = mono_custom_attrs_from_method(method);

    if (attributes) {
        for (i = 0; i < attributes->num_attrs; ++i) {
            MonoClass *klass = attributes->attrs [i].ctor->klass;
            if (strcmp (klass->image->assembly_name, attr_assembly) ==
0) {
                if (strcmp (klass->name_space, attr_namespace) == 0)
                    if (strcmp (klass->name, attr) == 0)
                        return TRUE;
            }
        }
        mono_custom_attrs_free (attributes); 
    }
 
    return FALSE;
}

gboolean
mono_class_has_custom_attr_partial (MonoClass *klass, const char
*attr_assembly, const char *attr_namespace, const char *attr)
{
    MonoCustomAttrInfo *attributes;

    if (attr_assembly != NULL)
        if (!mono_image_has_assembly_ref(klass->image, attr_assembly)
            return FALSE;

    attributes = mono_custom_attrs_from_class(klass);

    if (attributes) {
        for (i = 0; i < attributes->num_attrs; ++i) {
            MonoClass *klass = attributes->attrs [i].ctor->klass;
            if (strcmp (klass->image->assembly_name, attr_assembly) ==
0) {
                if (strcmp (klass->name_space, attr_namespace) == 0)
                    if (strcmp (klass->name, attr) == 0)
                        return TRUE;
            }
        }
        mono_custom_attrs_free (attributes); 
    }
 
    return FALSE;
}
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkl7c0IACgkQ1jvea6V8vHIZ2gCdGGDm0jbOLwmenqjMoiOBUtn9
VjgAnAjMyeWWAsib5PiBebyvU+DAwrE9
=SczF
-----END PGP SIGNATURE-----



More information about the Mono-devel-list mailing list