Skip to content

Commit

Permalink
Reduce some stack use and cleanup. (mono/mono#17809)
Browse files Browse the repository at this point in the history


Commit migrated from mono/mono@6eea4a1
  • Loading branch information
jaykrell authored and akoeplinger committed Jan 14, 2020
1 parent 0f4241a commit 6ccd907
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 63 deletions.
35 changes: 16 additions & 19 deletions src/mono/mono/metadata/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -4888,19 +4888,21 @@ create_unhandled_exception_eventargs (MonoObjectHandle exc, MonoError *error)
goto_if_nok (error, return_null);
g_assert (method);

MonoBoolean is_terminating;
is_terminating = TRUE;
gpointer args [2];
args [0] = MONO_HANDLE_RAW (exc); // FIXMEcoop
args [1] = &is_terminating;

MonoObjectHandle obj;
obj = mono_object_new_handle (mono_domain_get (), klass, error);
goto_if_nok (error, return_null);
{
MonoBoolean is_terminating = TRUE;

mono_runtime_invoke_handle_void (method, obj, args, error);
goto_if_nok (error, return_null);
return obj;
gpointer args [ ] = {
MONO_HANDLE_RAW (exc), // FIXMEcoop (ok as long as handles are pinning)
&is_terminating
};

MonoObjectHandle obj = mono_object_new_handle (mono_domain_get (), klass, error);
goto_if_nok (error, return_null);

mono_runtime_invoke_handle_void (method, obj, args, error);
goto_if_nok (error, return_null);
return obj;
}

return_null:
return MONO_HANDLE_NEW (MonoObject, NULL);
Expand Down Expand Up @@ -9100,9 +9102,7 @@ mono_load_remote_field_new_checked (MonoObject *this_obj, MonoClass *klass, Mono

/* MonoType *type = m_class_get_byval_arg (klass); */

gpointer args[2];
args [0] = &klass;
args [1] = &field;
gpointer args [ ] = { &klass, &field };

return mono_runtime_invoke_checked (tp_load, this_obj, args, error);
}
Expand Down Expand Up @@ -9215,10 +9215,7 @@ mono_store_remote_field_new_checked (MonoObject *this_obj, MonoClass *klass, Mon

MONO_STATIC_POINTER_INIT_END (MonoMethod, tp_store)

gpointer args[3];
args [0] = &klass;
args [1] = &field;
args [2] = arg;
gpointer args [ ] = { &klass, &field, arg };

mono_runtime_invoke_checked (tp_store, this_obj, args, error);
return is_ok (error);
Expand Down
28 changes: 15 additions & 13 deletions src/mono/mono/metadata/reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -982,8 +982,6 @@ add_parameter_object_to_array (MonoDomain *domain, MonoMethod *method, MonoObjec
ctor = m;
}

void *args [16];

MonoReflectionTypeHandle rt;
rt = mono_type_get_object_handle (domain, sig_param, error);
goto_if_nok (error, leave);
Expand Down Expand Up @@ -1036,17 +1034,21 @@ add_parameter_object_to_array (MonoDomain *domain, MonoMethod *method, MonoObjec
}

/* internal RuntimeParameterInfo (string name, Type type, int position, int attrs, object defaultValue, MemberInfo member, MarshalAsAttribute marshalAs) */
args [0] = MONO_HANDLE_RAW (name_str);
args [1] = MONO_HANDLE_RAW (rt);
args [2] = &idx;
int attrs;
attrs = sig_param->attrs;
args [3] = &attrs;
args [4] = MONO_HANDLE_RAW (def_value);
args [5] = MONO_HANDLE_RAW (member);
args [6] = MONO_HANDLE_RAW (mobj);

mono_runtime_invoke_handle_void (ctor, MONO_HANDLE_CAST (MonoObject, param), args, error);
{
int attrs = sig_param->attrs;

void *args [ ] = {
MONO_HANDLE_RAW (name_str),
MONO_HANDLE_RAW (rt),
&idx,
&attrs,
MONO_HANDLE_RAW (def_value),
MONO_HANDLE_RAW (member),
MONO_HANDLE_RAW (mobj)
};

mono_runtime_invoke_handle_void (ctor, MONO_HANDLE_CAST (MonoObject, param), args, error);
}
goto_if_nok (error, leave);

MONO_HANDLE_ARRAY_SETREF (dest, idx, param);
Expand Down
3 changes: 1 addition & 2 deletions src/mono/mono/metadata/sre.c
Original file line number Diff line number Diff line change
Expand Up @@ -4476,8 +4476,7 @@ mono_reflection_resolve_object (MonoImage *image, MonoObject *obj, MonoClass **h
mono_memory_barrier ();
resolve_method = m;
}
void *args [16];
args [0] = obj;
void *args [ ] = { obj };
obj = mono_runtime_invoke_checked (resolve_method, NULL, args, error);
goto_if_nok (error, return_null);
g_assert (obj);
Expand Down
18 changes: 6 additions & 12 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -5308,13 +5308,12 @@ add_generic_class_with_depth (MonoAotCompile *acfg, MonoClass *klass, int depth,
MonoClass *tclass = mono_class_from_mono_type_internal (mono_class_get_generic_class (klass)->context.class_inst->type_argv [0]);
MonoClass *icomparable, *gcomparer, *icomparable_inst;
MonoGenericContext ctx;
MonoType *args [16];

memset (&ctx, 0, sizeof (ctx));

icomparable = mono_class_load_from_name (mono_defaults.corlib, "System", "IComparable`1");

args [0] = m_class_get_byval_arg (tclass);
MonoType *args [ ] = { m_class_get_byval_arg (tclass) };
ctx.class_inst = mono_metadata_get_generic_inst (1, args);

icomparable_inst = mono_class_inflate_generic_class_checked (icomparable, &ctx, error);
Expand All @@ -5336,13 +5335,12 @@ add_generic_class_with_depth (MonoAotCompile *acfg, MonoClass *klass, int depth,
MonoClass *tclass = mono_class_from_mono_type_internal (mono_class_get_generic_class (klass)->context.class_inst->type_argv [0]);
MonoClass *iface, *gcomparer, *iface_inst;
MonoGenericContext ctx;
MonoType *args [16];

memset (&ctx, 0, sizeof (ctx));

iface = mono_class_load_from_name (mono_defaults.corlib, "System", "IEquatable`1");
g_assert (iface);
args [0] = m_class_get_byval_arg (tclass);
MonoType *args [ ] = { m_class_get_byval_arg (tclass) };
ctx.class_inst = mono_metadata_get_generic_inst (1, args);

iface_inst = mono_class_inflate_generic_class_checked (iface, &ctx, error);
Expand All @@ -5364,14 +5362,13 @@ add_generic_class_with_depth (MonoAotCompile *acfg, MonoClass *klass, int depth,
MonoClass *enum_comparer;
MonoClass *tclass = mono_class_from_mono_type_internal (mono_class_get_generic_class (klass)->context.class_inst->type_argv [0]);
MonoGenericContext ctx;
MonoType *args [16];

if (m_class_is_enumtype (tclass)) {
MonoClass *enum_comparer_inst;
ERROR_DECL (error);

memset (&ctx, 0, sizeof (ctx));
args [0] = m_class_get_byval_arg (tclass);
MonoType *args [ ] = { m_class_get_byval_arg (tclass) };
ctx.class_inst = mono_metadata_get_generic_inst (1, args);

enum_comparer = mono_class_load_from_name (mono_defaults.corlib, "System.Collections.Generic", "EnumEqualityComparer`1");
Expand All @@ -5386,14 +5383,13 @@ add_generic_class_with_depth (MonoAotCompile *acfg, MonoClass *klass, int depth,
MonoClass *comparer;
MonoClass *tclass = mono_class_from_mono_type_internal (mono_class_get_generic_class (klass)->context.class_inst->type_argv [0]);
MonoGenericContext ctx;
MonoType *args [16];

if (m_class_is_enumtype (tclass)) {
MonoClass *comparer_inst;
ERROR_DECL (error);

memset (&ctx, 0, sizeof (ctx));
args [0] = m_class_get_byval_arg (tclass);
MonoType *args [ ] = { m_class_get_byval_arg (tclass) };
ctx.class_inst = mono_metadata_get_generic_inst (1, args);

comparer = mono_class_load_from_name (mono_defaults.corlib, "System.Collections.Generic", "ObjectComparer`1");
Expand All @@ -5409,7 +5405,6 @@ add_instances_of (MonoAotCompile *acfg, MonoClass *klass, MonoType **insts, int
{
int i;
MonoGenericContext ctx;
MonoType *args [16];

if (acfg->aot_opts.no_instances)
return;
Expand All @@ -5419,7 +5414,7 @@ add_instances_of (MonoAotCompile *acfg, MonoClass *klass, MonoType **insts, int
for (i = 0; i < ninsts; ++i) {
ERROR_DECL (error);
MonoClass *generic_inst;
args [0] = insts [i];
MonoType *args [ ] = { insts [i] };
ctx.class_inst = mono_metadata_get_generic_inst (1, args);
generic_inst = mono_class_inflate_generic_class_checked (klass, &ctx, error);
mono_error_assert_ok (error); /* FIXME don't swallow the error */
Expand Down Expand Up @@ -10384,7 +10379,6 @@ mono_aot_get_array_helper_from_wrapper (MonoMethod *method)
MonoMethod *m;
const char *prefix;
MonoGenericContext ctx;
MonoType *args [16];
char *mname, *iname, *s, *s2, *helper_name = NULL;

prefix = "System.Collections.Generic";
Expand All @@ -10409,7 +10403,7 @@ mono_aot_get_array_helper_from_wrapper (MonoMethod *method)
if (m->is_generic) {
ERROR_DECL (error);
memset (&ctx, 0, sizeof (ctx));
args [0] = m_class_get_byval_arg (m_class_get_element_class (method->klass));
MonoType *args [ ] = { m_class_get_byval_arg (m_class_get_element_class (method->klass)) };
ctx.method_inst = mono_metadata_get_generic_inst (1, args);
m = mono_class_inflate_generic_method_checked (m, &ctx, error);
g_assert (is_ok (error)); /* FIXME don't swallow the error */
Expand Down
7 changes: 3 additions & 4 deletions src/mono/mono/mini/debugger-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -4634,13 +4634,12 @@ set_set_notification_for_wait_completion_flag (DbgEngineStackFrame *frame)
gpointer builder = get_async_method_builder (frame);
g_assert (builder);

void* args [1];
gboolean arg = TRUE;
ERROR_DECL (error);
args [0] = &arg;
MonoMethod* method = get_set_notification_method (mono_class_from_mono_type_internal (builder_field->type));
if (method == NULL)
return FALSE;
gboolean arg = TRUE;
ERROR_DECL (error);
void *args [ ] = { &arg };
mono_runtime_invoke_checked (method, builder, args, error);
mono_error_assert_ok (error);
return TRUE;
Expand Down
18 changes: 5 additions & 13 deletions src/mono/mono/mini/method-to-ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -2519,11 +2519,10 @@ mono_patch_info_rgctx_entry_new (MonoMemPool *mp, MonoMethod *method, gboolean i
static MonoInst*
emit_rgctx_fetch_inline (MonoCompile *cfg, MonoInst *rgctx, MonoJumpInfoRgctxEntry *entry)
{
MonoInst *args [16];
MonoInst *call;

// FIXME: No fastpath since the slot is not a compile time constant
args [0] = rgctx;
MonoInst *args [2] = { rgctx };
EMIT_NEW_AOTCONST (cfg, args [1], MONO_PATCH_INFO_RGCTX_SLOT_INDEX, entry);
if (entry->in_mrgctx)
call = mono_emit_jit_icall (cfg, mono_fill_method_rgctx, args);
Expand Down Expand Up @@ -3216,7 +3215,6 @@ handle_alloc (MonoCompile *cfg, MonoClass *klass, gboolean for_box, int context_
if (context_used) {
MonoInst *data;
MonoRgctxInfoType rgctx_info;
MonoInst *iargs [2];
gboolean known_instance_size = !mini_is_gsharedvt_klass (klass);

MonoMethod *managed_alloc = mono_gc_get_managed_allocator (klass, for_box, known_instance_size);
Expand Down Expand Up @@ -3673,7 +3671,7 @@ handle_constrained_gsharedvt_call (MonoCompile *cfg, MonoMethod *cmethod, MonoMe
}
}
if (supported) {
MonoInst *args [16];
MonoInst *args [5];

/*
* This case handles calls to
Expand Down Expand Up @@ -5250,12 +5248,11 @@ handle_call_res_devirt (MonoCompile *cfg, MonoMethod *cmethod, MonoInst *call_re
MonoType *param_type = mono_class_get_generic_class (cmethod->klass)->context.class_inst->type_argv [0];
MonoClass *inst;
MonoGenericContext ctx;
MonoType *args [16];
ERROR_DECL (error);

memset (&ctx, 0, sizeof (ctx));

args [0] = param_type;
MonoType *args [ ] = { param_type };
ctx.class_inst = mono_metadata_get_generic_inst (1, args);

inst = mono_class_inflate_generic_class_checked (mono_class_get_iequatable_class (), &ctx, error);
Expand Down Expand Up @@ -5825,10 +5822,9 @@ emit_setret (MonoCompile *cfg, MonoInst *val)
} else {
#ifdef MONO_ARCH_SOFT_FLOAT_FALLBACK
if (COMPILE_SOFT_FLOAT (cfg) && !ret_type->byref && ret_type->type == MONO_TYPE_R4) {
MonoInst *iargs [1];
MonoInst *conv;

iargs [0] = val;
MonoInst *iargs [ ] = { val };
conv = mono_emit_jit_icall (cfg, mono_fload_r4_arg, iargs);
mono_arch_emit_setret (cfg, cfg->method, conv);
} else {
Expand Down Expand Up @@ -7745,11 +7741,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
MonoInst *val = sp [fsig->param_count];

if (val->type == STACK_OBJ) {
MonoInst *iargs [2];

iargs [0] = sp [0];
iargs [1] = val;

MonoInst *iargs [ ] = { sp [0], val };
mono_emit_jit_icall (cfg, mono_helper_stelem_ref_check, iargs);
}

Expand Down

0 comments on commit 6ccd907

Please sign in to comment.