Skip to content

Commit

Permalink
Use an unboxed func ptr mono_marshal_get_native_func_wrapper_indirect
Browse files Browse the repository at this point in the history
Add support for the EMIT_NATIVE_WRAPPER_FUNC_PARAM_UNBOXED flag to mono_marshal_emit_native_wrapper
  • Loading branch information
lambdageek committed Jan 5, 2021
1 parent b93e932 commit 25b94ac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
7 changes: 4 additions & 3 deletions src/mono/mono/metadata/marshal-ilgen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,6 @@ emit_native_wrapper_ilgen (MonoImage *image, MonoMethodBuilder *mb, MonoMethodSi
gboolean aot = (flags & EMIT_NATIVE_WRAPPER_AOT) != 0;
gboolean check_exceptions = (flags & EMIT_NATIVE_WRAPPER_CHECK_EXCEPTIONS) != 0;
gboolean func_param = (flags & EMIT_NATIVE_WRAPPER_FUNC_PARAM) != 0;
/* TODO: make use of func_param_unboxed */
gboolean func_param_unboxed = (flags & EMIT_NATIVE_WRAPPER_FUNC_PARAM_UNBOXED) != 0;
gboolean skip_gc_trans = (flags & EMIT_NATIVE_WRAPPER_SKIP_GC_TRANS) != 0;
EmitMarshalContext m;
Expand Down Expand Up @@ -2146,8 +2145,10 @@ emit_native_wrapper_ilgen (MonoImage *image, MonoMethodBuilder *mb, MonoMethodSi
/* call the native method */
if (func_param) {
mono_mb_emit_byte (mb, CEE_LDARG_0);
mono_mb_emit_op (mb, CEE_UNBOX, mono_defaults.int_class);
mono_mb_emit_byte (mb, CEE_LDIND_I);
if (!func_param_unboxed) {
mono_mb_emit_op (mb, CEE_UNBOX, mono_defaults.int_class);
mono_mb_emit_byte (mb, CEE_LDIND_I);
}
if (piinfo && (piinfo->piflags & PINVOKE_ATTRIBUTE_SUPPORTS_LAST_ERROR) != 0) {
mono_mb_emit_byte (mb, MONO_CUSTOM_PREFIX);
mono_mb_emit_byte (mb, CEE_MONO_SAVE_LAST_ERROR);
Expand Down
3 changes: 1 addition & 2 deletions src/mono/mono/metadata/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -3670,9 +3670,8 @@ mono_marshal_get_native_func_wrapper_aot (MonoClass *klass)
*
* The wrapper is
*
* retType wrapper (fnPtrBoxed, arg1... argN) {
* retType wrapper (fnPtr, arg1... argN) {
* enter_gc_safe;
* fnPtr = unbox (fnPtrBoxed)
* ret = fnPtr (arg1, ... argN);
* exit_gc_safe;
* return ret;
Expand Down
13 changes: 2 additions & 11 deletions src/mono/mono/mini/method-to-ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -7080,15 +7080,6 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
#endif
/* Call the wrapper that will do the GC transition instead */
MonoMethod *wrapper = mono_marshal_get_native_func_wrapper_indirect (method->klass, fsig, cfg->compile_aot);
/* box the indirect function ptr */
/* FIXME: it would be nice if the wrapper didn't require a boxed argument */

MONO_INST_NEW (cfg, ins, OP_BOX);
ins->type = STACK_OBJ;
ins->klass = mono_defaults.int_class;
ins->sreg1 = addr->dreg;
ins->dreg = alloc_dreg (cfg, STACK_PTR);
MONO_ADD_INS (cfg->cbb, ins);

fsig = mono_method_signature_internal (wrapper);

Expand All @@ -7102,7 +7093,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
sp [1] = sp [0];
}

sp[0] = ins; /* n+1 args, first arg is the boxed address of the indirect method to call */
sp[0] = addr; /* n+1 args, first arg is the address of the indirect method to call */

g_assert (!fsig->hasthis && !fsig->pinvoke);

Expand All @@ -7111,7 +7102,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
int costs = inline_method (cfg, wrapper, fsig, sp, ip, cfg->real_offset, TRUE);
CHECK_CFG_EXCEPTION;
g_assert (costs > 0);
cfg->real_offset += 5; /* FIXME: why? */
cfg->real_offset += 5;
inline_costs += costs;
ins = sp[0];
} else {
Expand Down

0 comments on commit 25b94ac

Please sign in to comment.