Skip to content

Commit 0a8eed8

Browse files
committed
[jit] read DebuggableAttribute(DebuggingModes) ctor; move to metadata/
Pull is_jit_optimizer_disabled out of mini into metadata. Also support reading the DebuggingModes ctor
1 parent 768eb2e commit 0a8eed8

File tree

4 files changed

+82
-49
lines changed

4 files changed

+82
-49
lines changed

src/mono/mono/metadata/assembly-internals.h

+4
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,8 @@ mono_assembly_get_image_internal (MonoAssembly *assembly);
147147
void
148148
mono_set_assemblies_path_direct (char **path);
149149

150+
gboolean
151+
mono_assembly_is_jit_optimizer_disabled (MonoAssembly *assembly);
152+
153+
150154
#endif /* __MONO_METADATA_ASSEMBLY_INTERNALS_H__ */

src/mono/mono/metadata/assembly.c

+76
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ static const MonoBundledAssembly **bundles;
9595
static const MonoBundledSatelliteAssembly **satellite_bundles;
9696

9797
/* Class lazy loading functions */
98+
static GENERATE_TRY_GET_CLASS_WITH_CACHE (debuggable_attribute, "System.Diagnostics", "DebuggableAttribute")
99+
98100
static GENERATE_TRY_GET_CLASS_WITH_CACHE (internals_visible, "System.Runtime.CompilerServices", "InternalsVisibleToAttribute")
99101
static MonoAssembly*
100102
mono_assembly_invoke_search_hook_internal (MonoAssemblyLoadContext *alc, MonoAssembly *requesting, MonoAssemblyName *aname, gboolean postload);
@@ -3720,3 +3722,77 @@ mono_asmctx_get_name (const MonoAssemblyContext *asmctx)
37203722
g_assert (asmctx->kind >= 0 && asmctx->kind <= MONO_ASMCTX_LAST);
37213723
return names [asmctx->kind];
37223724
}
3725+
3726+
/**
3727+
* mono_assembly_is_jit_optimizer_disabled:
3728+
*
3729+
* \param assm the assembly
3730+
*
3731+
* Returns TRUE if the System.Diagnostics.DebuggableAttribute has the
3732+
* DebuggingModes.DisableOptimizations bit set.
3733+
*
3734+
*/
3735+
gboolean
3736+
mono_assembly_is_jit_optimizer_disabled (MonoAssembly *ass)
3737+
{
3738+
ERROR_DECL (error);
3739+
3740+
g_assert (ass);
3741+
if (ass->jit_optimizer_disabled_inited)
3742+
return ass->jit_optimizer_disabled;
3743+
3744+
MonoClass *klass =mono_class_try_get_debuggable_attribute_class ();
3745+
3746+
if (!klass) {
3747+
/* Linked away */
3748+
ass->jit_optimizer_disabled = FALSE;
3749+
mono_memory_barrier ();
3750+
ass->jit_optimizer_disabled_inited = TRUE;
3751+
return FALSE;
3752+
}
3753+
3754+
gboolean disable_opts = FALSE;
3755+
MonoCustomAttrInfo* attrs =mono_custom_attrs_from_assembly_checked (ass, FALSE, error);
3756+
mono_error_cleanup (error); /* FIXME don't swallow the error */
3757+
if (attrs) {
3758+
for (int i = 0; i < attrs->num_attrs; ++i) {
3759+
MonoCustomAttrEntry *attr = &attrs->attrs [i];
3760+
const gchar *p;
3761+
MonoMethodSignature *sig;
3762+
3763+
if (!attr->ctor || attr->ctor->klass != klass)
3764+
continue;
3765+
/* Decode the attribute. See reflection.c */
3766+
p = (const char*)attr->data;
3767+
g_assert (read16 (p) == 0x0001);
3768+
p += 2;
3769+
3770+
// FIXME: Support named parameters
3771+
sig = mono_method_signature_internal (attr->ctor);
3772+
MonoClass *param_class;
3773+
if (sig->param_count == 2 && sig->params [0]->type == MONO_TYPE_BOOLEAN && sig->params [1]->type == MONO_TYPE_BOOLEAN) {
3774+
3775+
/* Two boolean arguments */
3776+
p ++;
3777+
disable_opts = *p;
3778+
} else if (sig->param_count == 1 &&
3779+
sig->params[0]->type == MONO_TYPE_VALUETYPE &&
3780+
(param_class = mono_class_from_mono_type_internal (sig->params[0])) != NULL &&
3781+
m_class_is_enumtype (param_class) &&
3782+
!strcmp (m_class_get_name (param_class), "DebuggingModes")) {
3783+
/* System.Diagnostics.DebuggableAttribute+DebuggingModes */
3784+
int32_t flags = read32 (p);
3785+
p += 4;
3786+
disable_opts = (flags & 0x0100) != 0;
3787+
}
3788+
}
3789+
mono_custom_attrs_free (attrs);
3790+
}
3791+
3792+
ass->jit_optimizer_disabled = disable_opts;
3793+
mono_memory_barrier ();
3794+
ass->jit_optimizer_disabled_inited = TRUE;
3795+
3796+
return disable_opts;
3797+
3798+
}

src/mono/mono/metadata/metadata-internals.h

-1
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,6 @@ mono_assembly_name_parse_full (const char *name,
10831083
gboolean
10841084
mono_assembly_fill_assembly_name_full (MonoImage *image, MonoAssemblyName *aname, gboolean copyBlobs);
10851085

1086-
10871086
MONO_API guint32 mono_metadata_get_generic_param_row (MonoImage *image, guint32 token, guint32 *owner);
10881087

10891088
MonoGenericParam*

src/mono/mono/mini/method-to-ir.c

+2-48
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <mono/utils/memcheck.h>
4141
#include <mono/metadata/abi-details.h>
4242
#include <mono/metadata/assembly.h>
43+
#include <mono/metadata/assembly-internals.h>
4344
#include <mono/metadata/attrdefs.h>
4445
#include <mono/metadata/loader.h>
4546
#include <mono/metadata/tabledefs.h>
@@ -188,7 +189,6 @@ convert_value (MonoCompile *cfg, MonoType *type, MonoInst *ins);
188189
/* helper methods signatures */
189190

190191
/* type loading helpers */
191-
static GENERATE_TRY_GET_CLASS_WITH_CACHE (debuggable_attribute, "System.Diagnostics", "DebuggableAttribute")
192192
static GENERATE_GET_CLASS_WITH_CACHE (iequatable, "System", "IEquatable`1")
193193
static GENERATE_GET_CLASS_WITH_CACHE (geqcomparer, "System.Collections.Generic", "GenericEqualityComparer`1");
194194

@@ -5339,58 +5339,12 @@ is_exception_class (MonoClass *klass)
53395339
static gboolean
53405340
is_jit_optimizer_disabled (MonoMethod *m)
53415341
{
5342-
ERROR_DECL (error);
53435342
MonoAssembly *ass = m_class_get_image (m->klass)->assembly;
5344-
MonoCustomAttrInfo* attrs;
5345-
MonoClass *klass;
5346-
int i;
5347-
gboolean val = FALSE;
53485343

53495344
g_assert (ass);
53505345
if (ass->jit_optimizer_disabled_inited)
53515346
return ass->jit_optimizer_disabled;
5352-
5353-
klass = mono_class_try_get_debuggable_attribute_class ();
5354-
5355-
if (!klass) {
5356-
/* Linked away */
5357-
ass->jit_optimizer_disabled = FALSE;
5358-
mono_memory_barrier ();
5359-
ass->jit_optimizer_disabled_inited = TRUE;
5360-
return FALSE;
5361-
}
5362-
5363-
attrs = mono_custom_attrs_from_assembly_checked (ass, FALSE, error);
5364-
mono_error_cleanup (error); /* FIXME don't swallow the error */
5365-
if (attrs) {
5366-
for (i = 0; i < attrs->num_attrs; ++i) {
5367-
MonoCustomAttrEntry *attr = &attrs->attrs [i];
5368-
const gchar *p;
5369-
MonoMethodSignature *sig;
5370-
5371-
if (!attr->ctor || attr->ctor->klass != klass)
5372-
continue;
5373-
/* Decode the attribute. See reflection.c */
5374-
p = (const char*)attr->data;
5375-
g_assert (read16 (p) == 0x0001);
5376-
p += 2;
5377-
5378-
// FIXME: Support named parameters
5379-
sig = mono_method_signature_internal (attr->ctor);
5380-
if (sig->param_count != 2 || sig->params [0]->type != MONO_TYPE_BOOLEAN || sig->params [1]->type != MONO_TYPE_BOOLEAN)
5381-
continue;
5382-
/* Two boolean arguments */
5383-
p ++;
5384-
val = *p;
5385-
}
5386-
mono_custom_attrs_free (attrs);
5387-
}
5388-
5389-
ass->jit_optimizer_disabled = val;
5390-
mono_memory_barrier ();
5391-
ass->jit_optimizer_disabled_inited = TRUE;
5392-
5393-
return val;
5347+
return mono_assembly_is_jit_optimizer_disabled (ass);
53945348
}
53955349

53965350
gboolean

0 commit comments

Comments
 (0)