Merge pull request #2183 from joelmartinez/monodoc-ecmacref-fix
[mono.git] / mono / mini / mini-trampolines.c
index 489cc1bf7dea8d0732caf394a4a587d8378336a1..fb6d1f62e1dc12978dcfddeabc8e587e5ec142aa 100644 (file)
@@ -23,7 +23,6 @@
  */
 guint8* mono_trampoline_code [MONO_TRAMPOLINE_NUM];
 
-static GHashTable *class_init_hash_addr;
 static GHashTable *rgctx_lazy_fetch_trampoline_hash;
 static GHashTable *rgctx_lazy_fetch_trampoline_hash_addr;
 static guint32 trampoline_calls, jit_trampolines, unbox_trampolines, static_rgctx_trampolines;
@@ -146,28 +145,43 @@ mono_create_static_rgctx_trampoline (MonoMethod *m, gpointer addr)
 #endif
 
 /*
- * Either IMPL_METHOD or AOT_ADDR will be set on return.
+ * mini_resolve_imt_method:
  *
- * MONO_NEVER_INLINE :
- * This works against problems when compiling with gcc 4.6 on arm. The 'then' part of
- * this line gets executed, even when the condition is false:
- *             if (impl && mono_method_needs_static_rgctx_invoke (impl, FALSE))
- *                     *need_rgctx_tramp = TRUE;
+ *   Resolve the actual method called when making an IMT call through VTABLE_SLOT with IMT_METHOD as the interface method.
+ *
+ * Either IMPL_METHOD or OUT_AOT_ADDR will be set on return.
  */
-static MONO_NEVER_INLINE gpointer*
-mono_convert_imt_slot_to_vtable_slot (gpointer* slot, MonoObject *this_argument, MonoMethod *imt_method, gboolean lookup_aot, MonoMethod **impl_method, gboolean *variance_used, gpointer *aot_addr)
+gpointer*
+mini_resolve_imt_method (MonoVTable *vt, gpointer *vtable_slot, MonoMethod *imt_method, MonoMethod **impl_method, gpointer *out_aot_addr, gboolean *out_need_rgctx_tramp, MonoMethod **variant_iface)
 {
-       MonoVTable *vt = this_argument->vtable;
-       int displacement = slot - ((gpointer*)vt);
-       MonoMethod *impl;
+       MonoMethod *impl = NULL, *generic_virtual = NULL;
+       gboolean lookup_aot, variance_used = FALSE, need_rgctx_tramp = FALSE;
+       gpointer addr;
+       guint8 *aot_addr = NULL;
+       int displacement = vtable_slot - ((gpointer*)vt);
        int interface_offset;
        int imt_slot = MONO_IMT_SIZE + displacement;
 
-       /*This has to be variance aware since imt_method can be from an interface that vt->klass doesn't directly implement*/
-       interface_offset = mono_class_interface_offset_with_variance (vt->klass, imt_method->klass, variance_used);
+       g_assert (imt_slot < MONO_IMT_SIZE);
 
+       /* This has to be variance aware since imt_method can be from an interface that vt->klass doesn't directly implement */
+       interface_offset = mono_class_interface_offset_with_variance (vt->klass, imt_method->klass, &variance_used);
        if (interface_offset < 0)
                g_error ("%s doesn't implement interface %s\n", mono_type_get_name_full (&vt->klass->byval_arg, 0), mono_type_get_name_full (&imt_method->klass->byval_arg, 0));
+
+       *variant_iface = NULL;
+       if (imt_method->is_inflated && ((MonoMethodInflated*)imt_method)->context.method_inst) {
+               /* Generic virtual method */
+               generic_virtual = imt_method;
+               need_rgctx_tramp = TRUE;
+       } else if (variance_used && mono_class_has_variant_generic_params (imt_method->klass)) {
+               *variant_iface = imt_method;
+       }
+
+       addr = NULL;
+       /* We can only use the AOT compiled code if we don't require further processing */
+       lookup_aot = !generic_virtual & !variant_iface;
+
        mono_vtable_build_imt_slot (vt, mono_method_get_imt_slot (imt_method));
 
        if (imt_method->is_inflated && ((MonoMethodInflated*)imt_method)->context.method_inst) {
@@ -189,25 +203,34 @@ mono_convert_imt_slot_to_vtable_slot (gpointer* slot, MonoObject *this_argument,
        } else {
                /* Avoid loading metadata or creating a generic vtable if possible */
                if (lookup_aot && !vt->klass->valuetype)
-                       *aot_addr = mono_aot_get_method_from_vt_slot (mono_domain_get (), vt, interface_offset + mono_method_get_vtable_slot (imt_method));
+                       aot_addr = mono_aot_get_method_from_vt_slot (mono_domain_get (), vt, interface_offset + mono_method_get_vtable_slot (imt_method));
                else
-                       *aot_addr = NULL;
-               if (*aot_addr)
+                       aot_addr = NULL;
+               if (aot_addr)
                        impl = NULL;
                else
                        impl = mono_class_get_vtable_entry (vt->klass, interface_offset + mono_method_get_vtable_slot (imt_method));
        }
 
+       if (impl && mono_method_needs_static_rgctx_invoke (impl, FALSE))
+               need_rgctx_tramp = TRUE;
+       if (impl && impl->wrapper_type == MONO_WRAPPER_MANAGED_TO_MANAGED) {
+               WrapperInfo *info = mono_marshal_get_wrapper_info (impl);
+
+               if (info && info->subtype == WRAPPER_SUBTYPE_GENERIC_ARRAY_HELPER)
+                       need_rgctx_tramp = TRUE;
+       }
        *impl_method = impl;
+       *out_need_rgctx_tramp = need_rgctx_tramp;
+       *out_aot_addr = aot_addr;
+
        DEBUG_IMT (printf ("mono_convert_imt_slot_to_vtable_slot: method = %s.%s.%s, imt_method = %s.%s.%s\n",
                                           method->klass->name_space, method->klass->name, method->name,
                                           imt_method->klass->name_space, imt_method->klass->name, imt_method->name));
 
-       g_assert (imt_slot < MONO_IMT_SIZE);
        if (vt->imt_collisions_bitmap & (1 << imt_slot)) {
                int slot = mono_method_get_vtable_index (imt_method);
                int vtable_offset;
-               gpointer *vtable_slot;
 
                g_assert (slot != -1);
                vtable_offset = interface_offset + slot;
@@ -216,7 +239,7 @@ mono_convert_imt_slot_to_vtable_slot (gpointer* slot, MonoObject *this_argument,
                return vtable_slot;
        } else {
                DEBUG_IMT (printf ("mono_convert_imt_slot_to_vtable_slot: slot %p[%d] is in the IMT, but not colliding\n", slot, imt_slot));
-               return slot;
+               return vtable_slot;
        }
 }
 
@@ -317,21 +340,18 @@ mini_add_method_trampoline (MonoMethod *m, gpointer compiled_method, gboolean ad
                }
        }
 
-       if (ji)
+       if (ji && !ji->is_trampoline)
                jmethod = jinfo_get_method (ji);
        if (callee_gsharedvt && mini_is_gsharedvt_variable_signature (mono_method_signature (jmethod))) {
-               MonoGenericSharingContext *gsctx;
                MonoMethodSignature *sig, *gsig;
 
                /* Here m is a generic instance, while ji->method is the gsharedvt method implementing it */
 
                /* Call from normal/gshared code to gsharedvt code with variable signature */
-               gsctx = mono_jit_info_get_generic_sharing_context (ji);
-
                sig = mono_method_signature (m);
                gsig = mono_method_signature (jmethod);
 
-               addr = mini_get_gsharedvt_wrapper (TRUE, addr, sig, gsig, gsctx, -1, FALSE);
+               addr = mini_get_gsharedvt_wrapper (TRUE, addr, sig, gsig, -1, FALSE);
 
                //printf ("IN: %s\n", mono_method_full_name (m, TRUE));
        }
@@ -341,11 +361,14 @@ mini_add_method_trampoline (MonoMethod *m, gpointer compiled_method, gboolean ad
                /* FIXME: ji->from_aot is not set for llvm methods */
                if (ji && (ji->from_aot || mono_aot_only)) {
                        /* In AOT mode, compiled_method points to one of the InternalArray methods in Array. */
-                       if (mono_method_needs_static_rgctx_invoke (jinfo_get_method (ji), TRUE))
+                       if (!mono_llvm_only && mono_method_needs_static_rgctx_invoke (jinfo_get_method (ji), TRUE))
                                add_static_rgctx_tramp = TRUE;
                }
        }
 
+       if (mono_llvm_only)
+               add_static_rgctx_tramp = FALSE;
+
        if (add_static_rgctx_tramp)
                addr = mono_create_static_rgctx_trampoline (m, addr);
 
@@ -368,7 +391,7 @@ common_call_trampoline_inner (mgreg_t *regs, guint8 *code, MonoMethod *m, MonoVT
        MonoMethod *declaring = NULL;
        MonoMethod *generic_virtual = NULL, *variant_iface = NULL;
        int context_used;
-       gboolean imt_call, virtual, variance_used = FALSE;
+       gboolean imt_call, virtual;
        gpointer *orig_vtable_slot, *vtable_slot_to_patch = NULL;
        MonoJitInfo *ji = NULL;
 
@@ -387,45 +410,26 @@ common_call_trampoline_inner (mgreg_t *regs, guint8 *code, MonoMethod *m, MonoVT
 
        /* IMT call */
        if (imt_call) {
-               MonoMethod *impl_method = NULL;
+               MonoMethod *imt_method = NULL, *impl_method = NULL;
                MonoObject *this_arg;
 
-               m = mono_arch_find_imt_method (regs, code);
                g_assert (vtable_slot);
 
+               imt_method = mono_arch_find_imt_method (regs, code);
                this_arg = mono_arch_get_this_arg_from_call (regs, code);
 
                if (mono_object_is_transparent_proxy (this_arg)) {
                        /* Use the slow path for now */
-                   m = mono_object_get_virtual_method (this_arg, m);
+                   m = mono_object_get_virtual_method (this_arg, imt_method);
                        vtable_slot_to_patch = NULL;
                } else {
-                       gboolean lookup_aot;
-
-                       mono_class_interface_offset_with_variance (vt->klass, m->klass, &variance_used);
-
-                       if (m->is_inflated && ((MonoMethodInflated*)m)->context.method_inst) {
+                       if (imt_method->is_inflated && ((MonoMethodInflated*)imt_method)->context.method_inst) {
                                /* Generic virtual method */
-                               generic_virtual = m;
-                               need_rgctx_tramp = TRUE;
-                       } else if (variance_used && mono_class_has_variant_generic_params (m->klass)) {
-                               variant_iface = m;
-                       }
-
-                       addr = NULL;
-                       /* We can only use the AOT compiled code if we don't require further processing */
-                       lookup_aot = !generic_virtual & !variant_iface;
-                       vtable_slot = mono_convert_imt_slot_to_vtable_slot (vtable_slot, this_arg, m, lookup_aot, &impl_method, &variance_used, &addr);
-
-                       if (impl_method && mono_method_needs_static_rgctx_invoke (impl_method, FALSE))
+                               generic_virtual = imt_method;
                                need_rgctx_tramp = TRUE;
-                       if (impl_method && impl_method->wrapper_type == MONO_WRAPPER_MANAGED_TO_MANAGED) {
-                               WrapperInfo *info = mono_marshal_get_wrapper_info (impl_method);
-
-                               if (info && info->subtype == WRAPPER_SUBTYPE_GENERIC_ARRAY_HELPER)
-                                       need_rgctx_tramp = TRUE;
                        }
 
+                       vtable_slot = mini_resolve_imt_method (vt, vtable_slot, imt_method, &impl_method, &addr, &need_rgctx_tramp, &variant_iface);
                        /* This is the vcall slot which gets called through the IMT thunk */
                        vtable_slot_to_patch = vtable_slot;
 
@@ -439,10 +443,6 @@ common_call_trampoline_inner (mgreg_t *regs, guint8 *code, MonoMethod *m, MonoVT
                                return mono_create_ftnptr (mono_domain_get (), addr);
                        }
 
-                       /*
-                        * mono_convert_imt_slot_to_vtable_slot () also gives us the method that is supposed
-                        * to be called, so we compile it and go ahead as usual.
-                        */
                        m = impl_method;
                }
        }
@@ -706,7 +706,7 @@ mono_magic_trampoline (mgreg_t *regs, guint8 *code, gpointer arg, guint8* tramp)
 static gpointer
 mono_vcall_trampoline (mgreg_t *regs, guint8 *code, int slot, guint8 *tramp)
 {
-       MonoObject *this;
+       MonoObject *this_arg;
        MonoVTable *vt;
        gpointer *vtable_slot;
        MonoMethod *m;
@@ -725,10 +725,10 @@ mono_vcall_trampoline (mgreg_t *regs, guint8 *code, int slot, guint8 *tramp)
        /*
         * Obtain the vtable from the 'this' arg.
         */
-       this = mono_arch_get_this_arg_from_call (regs, code);
-       g_assert (this);
+       this_arg = mono_arch_get_this_arg_from_call (regs, code);
+       g_assert (this_arg);
 
-       vt = this->vtable;
+       vt = this_arg->vtable;
 
        if (slot >= 0) {
                /* Normal virtual call */
@@ -873,43 +873,6 @@ mono_aot_plt_trampoline (mgreg_t *regs, guint8 *code, guint8 *aot_module,
 }
 #endif
 
-/**
- * mono_class_init_trampoline:
- *
- * This method calls mono_runtime_class_init () to run the static constructor
- * for the type, then patches the caller code so it is not called again.
- */
-void
-mono_class_init_trampoline (mgreg_t *regs, guint8 *code, MonoVTable *vtable, guint8 *tramp)
-{
-       guint8 *plt_entry = mono_aot_get_plt_entry (code);
-
-       trampoline_calls ++;
-
-       mono_runtime_class_init (vtable);
-
-       if (vtable->initialized) {
-               if (plt_entry)
-                       mono_aot_patch_plt_entry (code, plt_entry, NULL, regs, mini_get_nullified_class_init_trampoline ());
-               else
-                       mono_arch_nullify_class_init_trampoline (code, regs);
-       }
-}
-
-/**
- * mono_generic_class_init_trampoline:
- *
- * This method calls mono_runtime_class_init () to run the static constructor
- * for the type.
- */
-void
-mono_generic_class_init_trampoline (mgreg_t *regs, guint8 *code, MonoVTable *vtable, guint8 *tramp)
-{
-       trampoline_calls ++;
-
-       mono_runtime_class_init (vtable);
-}
-
 static gpointer
 mono_rgctx_lazy_fetch_trampoline (mgreg_t *regs, guint8 *code, gpointer data, guint8 *tramp)
 {
@@ -936,29 +899,6 @@ mono_rgctx_lazy_fetch_trampoline (mgreg_t *regs, guint8 *code, gpointer data, gu
                return mono_class_fill_runtime_generic_context (arg, index);
 }
 
-void
-mono_monitor_enter_trampoline (mgreg_t *regs, guint8 *code, MonoObject *obj, guint8 *tramp)
-{
-       mono_monitor_enter (obj);
-}
-
-void
-mono_monitor_enter_v4_trampoline (mgreg_t *regs, guint8 *code, MonoObject *obj, guint8 *tramp)
-{
-#ifdef MONO_ARCH_MONITOR_LOCK_TAKEN_REG
-       char *lock_taken = (char*)regs [MONO_ARCH_MONITOR_LOCK_TAKEN_REG];
-       mono_monitor_enter_v4 (obj, lock_taken);
-#else
-       g_assert_not_reached ();
-#endif
-}
-
-void
-mono_monitor_exit_trampoline (mgreg_t *regs, guint8 *code, MonoObject *obj, guint8 *tramp)
-{
-       mono_monitor_exit (obj);
-}
-
 /*
  * Precompute data to speed up mono_delegate_trampoline ().
  * METHOD might be NULL.
@@ -1065,7 +1005,10 @@ mono_delegate_trampoline (mgreg_t *regs, guint8 *code, gpointer *arg, guint8* tr
                                }
                        }
                }
-       } else {
+       // If "delegate->method_ptr" is null mono_get_addr_from_ftnptr will fail if
+       // ftnptrs are being used.  "method" would end up null on archtitectures without
+       // ftnptrs so we can just skip this.
+       } else if (delegate->method_ptr) {
                ji = mono_jit_info_table_find (domain, mono_get_addr_from_ftnptr (delegate->method_ptr));
                if (ji)
                        method = jinfo_get_method (ji);
@@ -1211,7 +1154,7 @@ mono_create_handler_block_trampoline (void)
                gpointer tmp;
 
                tmp = mono_arch_create_handler_block_trampoline (&info, FALSE);
-               mono_tramp_info_register (info);
+               mono_tramp_info_register (info, NULL);
                mono_memory_barrier ();
                code = tmp;
        }
@@ -1234,10 +1177,6 @@ mono_get_trampoline_func (MonoTrampolineType tramp_type)
        case MONO_TRAMPOLINE_JIT:
        case MONO_TRAMPOLINE_JUMP:
                return mono_magic_trampoline;
-       case MONO_TRAMPOLINE_CLASS_INIT:
-               return mono_class_init_trampoline;
-       case MONO_TRAMPOLINE_GENERIC_CLASS_INIT:
-               return mono_generic_class_init_trampoline;
        case MONO_TRAMPOLINE_RGCTX_LAZY_FETCH:
                return mono_rgctx_lazy_fetch_trampoline;
 #ifdef MONO_ARCH_AOT_SUPPORTED
@@ -1254,12 +1193,6 @@ mono_get_trampoline_func (MonoTrampolineType tramp_type)
        case MONO_TRAMPOLINE_GENERIC_VIRTUAL_REMOTING:
                return mono_generic_virtual_remoting_trampoline;
 #endif
-       case MONO_TRAMPOLINE_MONITOR_ENTER:
-               return mono_monitor_enter_trampoline;
-       case MONO_TRAMPOLINE_MONITOR_ENTER_V4:
-               return mono_monitor_enter_v4_trampoline;
-       case MONO_TRAMPOLINE_MONITOR_EXIT:
-               return mono_monitor_exit_trampoline;
        case MONO_TRAMPOLINE_VCALL:
                return mono_vcall_trampoline;
 #ifdef MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD
@@ -1279,7 +1212,7 @@ create_trampoline_code (MonoTrampolineType tramp_type)
        guchar *code;
 
        code = mono_arch_create_generic_trampoline (tramp_type, &info, FALSE);
-       mono_tramp_info_register (info);
+       mono_tramp_info_register (info, NULL);
 
        return code;
 }
@@ -1294,8 +1227,6 @@ mono_trampolines_init (void)
 
        mono_trampoline_code [MONO_TRAMPOLINE_JIT] = create_trampoline_code (MONO_TRAMPOLINE_JIT);
        mono_trampoline_code [MONO_TRAMPOLINE_JUMP] = create_trampoline_code (MONO_TRAMPOLINE_JUMP);
-       mono_trampoline_code [MONO_TRAMPOLINE_CLASS_INIT] = create_trampoline_code (MONO_TRAMPOLINE_CLASS_INIT);
-       mono_trampoline_code [MONO_TRAMPOLINE_GENERIC_CLASS_INIT] = create_trampoline_code (MONO_TRAMPOLINE_GENERIC_CLASS_INIT);
        mono_trampoline_code [MONO_TRAMPOLINE_RGCTX_LAZY_FETCH] = create_trampoline_code (MONO_TRAMPOLINE_RGCTX_LAZY_FETCH);
 #ifdef MONO_ARCH_AOT_SUPPORTED
        mono_trampoline_code [MONO_TRAMPOLINE_AOT] = create_trampoline_code (MONO_TRAMPOLINE_AOT);
@@ -1306,9 +1237,6 @@ mono_trampolines_init (void)
 #ifndef DISABLE_REMOTING
        mono_trampoline_code [MONO_TRAMPOLINE_GENERIC_VIRTUAL_REMOTING] = create_trampoline_code (MONO_TRAMPOLINE_GENERIC_VIRTUAL_REMOTING);
 #endif
-       mono_trampoline_code [MONO_TRAMPOLINE_MONITOR_ENTER] = create_trampoline_code (MONO_TRAMPOLINE_MONITOR_ENTER);
-       mono_trampoline_code [MONO_TRAMPOLINE_MONITOR_ENTER_V4] = create_trampoline_code (MONO_TRAMPOLINE_MONITOR_ENTER_V4);
-       mono_trampoline_code [MONO_TRAMPOLINE_MONITOR_EXIT] = create_trampoline_code (MONO_TRAMPOLINE_MONITOR_EXIT);
        mono_trampoline_code [MONO_TRAMPOLINE_VCALL] = create_trampoline_code (MONO_TRAMPOLINE_VCALL);
 #ifdef MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD
        mono_trampoline_code [MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD] = create_trampoline_code (MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD);
@@ -1324,8 +1252,6 @@ mono_trampolines_init (void)
 void
 mono_trampolines_cleanup (void)
 {
-       if (class_init_hash_addr)
-               g_hash_table_destroy (class_init_hash_addr);
        if (rgctx_lazy_fetch_trampoline_hash)
                g_hash_table_destroy (rgctx_lazy_fetch_trampoline_hash);
        if (rgctx_lazy_fetch_trampoline_hash_addr)
@@ -1351,42 +1277,6 @@ mono_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type, M
                return mono_arch_create_specific_trampoline (arg1, tramp_type, domain, code_len);
 }
 
-gpointer
-mono_create_class_init_trampoline (MonoVTable *vtable)
-{
-       gpointer code, ptr;
-       MonoDomain *domain = vtable->domain;
-
-       g_assert (!vtable->klass->generic_container);
-
-       /* previously created trampoline code */
-       mono_domain_lock (domain);
-       ptr = 
-               g_hash_table_lookup (domain_jit_info (domain)->class_init_trampoline_hash,
-                                                                 vtable);
-       mono_domain_unlock (domain);
-       if (ptr)
-               return ptr;
-
-       code = mono_create_specific_trampoline (vtable, MONO_TRAMPOLINE_CLASS_INIT, domain, NULL);
-
-       ptr = mono_create_ftnptr (domain, code);
-
-       /* store trampoline address */
-       mono_domain_lock (domain);
-       g_hash_table_insert (domain_jit_info (domain)->class_init_trampoline_hash,
-                                                         vtable, ptr);
-       mono_domain_unlock (domain);
-
-       mono_trampolines_lock ();
-       if (!class_init_hash_addr)
-               class_init_hash_addr = g_hash_table_new (NULL, NULL);
-       g_hash_table_insert (class_init_hash_addr, ptr, vtable);
-       mono_trampolines_unlock ();
-
-       return ptr;
-}
-
 gpointer
 mono_create_jump_trampoline (MonoDomain *domain, MonoMethod *method, gboolean add_sync_wrapper)
 {
@@ -1404,6 +1294,9 @@ mono_create_jump_trampoline (MonoDomain *domain, MonoMethod *method, gboolean ad
        if (code && !ji->has_generic_jit_info && !(method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED))
                return code;
 
+       if (mono_llvm_only)
+               return mono_jit_compile_method (method);
+
        mono_domain_lock (domain);
        code = g_hash_table_lookup (domain_jit_info (domain)->jump_trampoline_hash, method);
        mono_domain_unlock (domain);
@@ -1432,6 +1325,12 @@ mono_create_jump_trampoline (MonoDomain *domain, MonoMethod *method, gboolean ad
        return ji->code_start;
 }
 
+static void
+method_not_found (void)
+{
+       g_assert_not_reached ();
+}
+
 gpointer
 mono_create_jit_trampoline_in_domain (MonoDomain *domain, MonoMethod *method)
 {
@@ -1443,6 +1342,14 @@ mono_create_jit_trampoline_in_domain (MonoDomain *domain, MonoMethod *method)
                
                if (code)
                        return code;
+               if (mono_llvm_only) {
+                       if (method->wrapper_type == MONO_WRAPPER_PROXY_ISINST || method->wrapper_type == MONO_WRAPPER_LDFLD_REMOTE ||
+                               method->wrapper_type == MONO_WRAPPER_STFLD_REMOTE)
+                               /* These wrappers are not generated */
+                               return method_not_found;
+                       /* Methods are lazily initialized on first call, so this can't lead recursion */
+                       return mono_compile_method (method);
+               }
        }
 
        mono_domain_lock (domain);
@@ -1526,9 +1433,18 @@ mono_create_delegate_trampoline_info (MonoDomain *domain, MonoClass *klass, Mono
        return tramp_info;
 }
 
+static void
+no_delegate_trampoline (void)
+{
+       g_assert_not_reached ();
+}
+
 gpointer
 mono_create_delegate_trampoline (MonoDomain *domain, MonoClass *klass)
 {
+       if (mono_llvm_only)
+               return no_delegate_trampoline;
+
        return mono_create_delegate_trampoline_info (domain, klass, NULL)->invoke_impl;
 }
 
@@ -1563,7 +1479,7 @@ mono_create_rgctx_lazy_fetch_trampoline (guint32 offset)
                ptr = mono_aot_get_lazy_fetch_trampoline (offset);
        } else {
                tramp = mono_arch_create_rgctx_lazy_fetch_trampoline (offset, &info, FALSE);
-               mono_tramp_info_register (info);
+               mono_tramp_info_register (info, NULL);
                ptr = mono_create_ftnptr (mono_get_root_domain (), tramp);
        }
 
@@ -1586,95 +1502,6 @@ mono_create_rgctx_lazy_fetch_trampoline (guint32 offset)
 
        return ptr;
 }
-
-gpointer
-mono_create_monitor_enter_trampoline (void)
-{
-       static gpointer code;
-
-       if (mono_aot_only) {
-               if (!code)
-                       code = mono_aot_get_trampoline ("monitor_enter_trampoline");
-               return code;
-       }
-
-#ifdef MONO_ARCH_MONITOR_OBJECT_REG
-       mono_trampolines_lock ();
-
-       if (!code) {
-               MonoTrampInfo *info;
-
-               code = mono_arch_create_monitor_enter_trampoline (&info, FALSE, FALSE);
-               mono_tramp_info_register (info);
-       }
-
-       mono_trampolines_unlock ();
-#else
-       code = NULL;
-       g_assert_not_reached ();
-#endif
-
-       return code;
-}
-
-gpointer
-mono_create_monitor_enter_v4_trampoline (void)
-{
-       static gpointer code;
-
-       if (mono_aot_only) {
-               if (!code)
-                       code = mono_aot_get_trampoline ("monitor_enter_v4_trampoline");
-               return code;
-       }
-
-#if defined(MONO_ARCH_MONITOR_OBJECT_REG) && defined(MONO_ARCH_MONITOR_LOCK_TAKEN_REG)
-       mono_trampolines_lock ();
-
-       if (!code) {
-               MonoTrampInfo *info;
-
-               code = mono_arch_create_monitor_enter_trampoline (&info, TRUE, FALSE);
-               mono_tramp_info_register (info);
-       }
-
-       mono_trampolines_unlock ();
-#else
-       code = NULL;
-       g_assert_not_reached ();
-#endif
-
-       return code;
-}
-
-gpointer
-mono_create_monitor_exit_trampoline (void)
-{
-       static gpointer code;
-
-       if (mono_aot_only) {
-               if (!code)
-                       code = mono_aot_get_trampoline ("monitor_exit_trampoline");
-               return code;
-       }
-
-#ifdef MONO_ARCH_MONITOR_OBJECT_REG
-       mono_trampolines_lock ();
-
-       if (!code) {
-               MonoTrampInfo *info;
-
-               code = mono_arch_create_monitor_exit_trampoline (&info, FALSE);
-               mono_tramp_info_register (info);
-       }
-
-       mono_trampolines_unlock ();
-#else
-       code = NULL;
-       g_assert_not_reached ();
-#endif
-       return code;
-}
  
 #ifdef MONO_ARCH_LLVM_SUPPORTED
 /*
@@ -1696,20 +1523,6 @@ mono_create_llvm_imt_trampoline (MonoDomain *domain, MonoMethod *m, int vt_offse
 }
 #endif
 
-MonoVTable*
-mono_find_class_init_trampoline_by_addr (gconstpointer addr)
-{
-       MonoVTable *res;
-
-       mono_trampolines_lock ();
-       if (class_init_hash_addr)
-               res = g_hash_table_lookup (class_init_hash_addr, addr);
-       else
-               res = NULL;
-       mono_trampolines_unlock ();
-       return res;
-}
-
 guint32
 mono_find_rgctx_lazy_fetch_trampoline_by_addr (gconstpointer addr)
 {
@@ -1733,17 +1546,12 @@ mono_find_rgctx_lazy_fetch_trampoline_by_addr (gconstpointer addr)
 static const char*tramp_names [MONO_TRAMPOLINE_NUM] = {
        "jit",
        "jump",
-       "class_init",
-       "generic_class_init",
        "rgctx_lazy_fetch",
        "aot",
        "aot_plt",
        "delegate",
        "restore_stack_prot",
        "generic_virtual_remoting",
-       "monitor_enter",
-       "monitor_enter_v4",
-       "monitor_exit",
        "vcall",
        "handler_block_guard"
 };
@@ -1786,30 +1594,6 @@ mono_get_rgctx_fetch_trampoline_name (int slot)
        return g_strdup_printf ("rgctx_fetch_trampoline_%s_%d", mrgctx ? "mrgctx" : "rgctx", index);
 }
 
-gpointer
-mini_get_nullified_class_init_trampoline (void)
-{
-       static gpointer nullified_class_init_trampoline;
-
-       if (!nullified_class_init_trampoline) {
-               gpointer tramp;
-               MonoTrampInfo *info;
-
-               if (mono_aot_only) {
-                       /* Not used */
-                       g_assert_not_reached ();
-                       tramp = NULL;
-               } else {
-                       tramp = mono_arch_get_nullified_class_init_trampoline (&info);
-                       mono_tramp_info_register (info);
-               }
-               mono_memory_barrier ();
-               nullified_class_init_trampoline = tramp;
-       }
-
-       return nullified_class_init_trampoline;
-}
-
 /*
  * mini_get_single_step_trampoline:
  *
@@ -1829,7 +1613,7 @@ mini_get_single_step_trampoline (void)
 #ifdef MONO_ARCH_HAVE_SDB_TRAMPOLINES
                        MonoTrampInfo *info;
                        tramp = mono_arch_create_sdb_trampoline (TRUE, &info, FALSE);
-                       mono_tramp_info_register (info);
+                       mono_tramp_info_register (info, NULL);
 #else
                        tramp = NULL;
                        g_assert_not_reached ();
@@ -1861,7 +1645,7 @@ mini_get_breakpoint_trampoline (void)
 #ifdef MONO_ARCH_HAVE_SDB_TRAMPOLINES
                        MonoTrampInfo *info;
                        tramp = mono_arch_create_sdb_trampoline (FALSE, &info, FALSE);
-                       mono_tramp_info_register (info);
+                       mono_tramp_info_register (info, NULL);
 #else
                        tramp = NULL;
                        g_assert_not_reached ();