From ec0afc0a0960ac5e9fc17deabb18d09e0c0dbff5 Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Wed, 31 Jul 2019 08:26:24 -0400 Subject: [PATCH] [jit] Optimize the initialize of MonoError locals. (mono/mono#15869) Previously, we would emit a call to memset since the struct is large (> 100 bytes). Only the error code field needs to be initialized. Commit migrated from https://github.com/mono/mono/commit/6223e7468892cd1371fc52a5d1fd0ac1c4e1b273 --- src/mono/mono/metadata/object-offsets.h | 2 ++ src/mono/mono/mini/decompose.c | 8 +++++++- src/mono/mono/utils/mono-error-internals.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/mono/mono/metadata/object-offsets.h b/src/mono/mono/metadata/object-offsets.h index 4a00df0..b1546d4 100644 --- a/src/mono/mono/metadata/object-offsets.h +++ b/src/mono/mono/metadata/object-offsets.h @@ -136,6 +136,8 @@ DECL_OFFSET(MonoProfilerCallContext, method) DECL_OFFSET(MonoProfilerCallContext, return_value) DECL_OFFSET(MonoProfilerCallContext, args) +DECL_OFFSET(MonoError, init) + #ifdef HAVE_SGEN_GC DECL_OFFSET(SgenClientThreadInfo, in_critical_region) DECL_OFFSET(SgenThreadInfo, tlab_next) diff --git a/src/mono/mono/mini/decompose.c b/src/mono/mono/mini/decompose.c index 97932ad..cded93c 100644 --- a/src/mono/mono/mini/decompose.c +++ b/src/mono/mono/mini/decompose.c @@ -1249,7 +1249,13 @@ mono_decompose_vtype_opts (MonoCompile *cfg) g_assert (ins->klass); EMIT_NEW_VARLOADA_VREG (cfg, dest, ins->dreg, m_class_get_byval_arg (ins->klass)); - mini_emit_initobj (cfg, dest, NULL, ins->klass); + + if (m_class_get_image (ins->klass) == mono_defaults.corlib && !strcmp (m_class_get_name (ins->klass), "MonoError")) { + // Used in icall wrappers, optimize initialization + MONO_EMIT_NEW_STORE_MEMBASE_IMM (cfg, OP_STOREI4_MEMBASE_IMM, dest->dreg, MONO_STRUCT_OFFSET (MonoError, init), 0); + } else { + mini_emit_initobj (cfg, dest, NULL, ins->klass); + } if (cfg->compute_gc_maps) { MonoInst *tmp; diff --git a/src/mono/mono/utils/mono-error-internals.h b/src/mono/mono/utils/mono-error-internals.h index 9df0dbe..3088d01 100644 --- a/src/mono/mono/utils/mono-error-internals.h +++ b/src/mono/mono/utils/mono-error-internals.h @@ -10,6 +10,7 @@ /*Keep in sync with MonoError*/ typedef struct { + // Written by JITted code guint16 error_code; guint16 flags; -- 2.7.4