[jit] Optimize the initialize of MonoError locals. (mono/mono#15869)
authorZoltan Varga <vargaz@gmail.com>
Wed, 31 Jul 2019 12:26:24 +0000 (08:26 -0400)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Wed, 31 Jul 2019 12:26:24 +0000 (14:26 +0200)
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
src/mono/mono/mini/decompose.c
src/mono/mono/utils/mono-error-internals.h

index 4a00df0..b1546d4 100644 (file)
@@ -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)
index 97932ad..cded93c 100644 (file)
@@ -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;
index 9df0dbe..3088d01 100644 (file)
@@ -10,6 +10,7 @@
 
 /*Keep in sync with MonoError*/
 typedef struct {
+       // Written by JITted code
        guint16 error_code;
        guint16 flags;