2 * tramp-x86.c: JIT trampoline code for x86
5 * Dietmar Maurer (dietmar@ximian.com)
7 * (C) 2001 Ximian, Inc.
13 #include <mono/metadata/appdomain.h>
14 #include <mono/metadata/metadata-internals.h>
15 #include <mono/metadata/marshal.h>
16 #include <mono/metadata/tabledefs.h>
17 #include <mono/metadata/mono-debug.h>
18 #include <mono/metadata/mono-debug-debugger.h>
19 #include <mono/metadata/monitor.h>
20 #include <mono/arch/x86/x86-codegen.h>
22 #ifdef HAVE_VALGRIND_MEMCHECK_H
23 #include <valgrind/memcheck.h>
29 static guint8* nullified_class_init_trampoline;
32 * mono_arch_get_unbox_trampoline:
33 * @gsctx: the generic sharing context
35 * @addr: pointer to native code for @m
37 * when value type methods are called through the vtable we need to unbox the
38 * this argument. This method returns a pointer to a trampoline which does
39 * unboxing before calling the method
42 mono_arch_get_unbox_trampoline (MonoGenericSharingContext *gsctx, MonoMethod *m, gpointer addr)
46 MonoDomain *domain = mono_domain_get ();
48 if (MONO_TYPE_ISSTRUCT (mono_method_signature (m)->ret))
51 mono_domain_lock (domain);
52 start = code = mono_code_manager_reserve (domain->code_mp, 16);
53 mono_domain_unlock (domain);
55 x86_alu_membase_imm (code, X86_ADD, X86_ESP, this_pos, sizeof (MonoObject));
56 x86_jump_code (code, addr);
57 g_assert ((code - start) < 16);
63 mono_arch_patch_callsite (guint8 *method_start, guint8 *orig_code, guint8 *addr)
67 gboolean can_write = mono_breakpoint_clean_code (method_start, orig_code, 8, buf, sizeof (buf));
70 if (mono_running_on_valgrind ())
73 /* go to the start of the call instruction
75 * address_byte = (m << 6) | (o << 3) | reg
76 * call opcode: 0xff address_byte displacement
82 if ((code [1] == 0xe8)) {
84 InterlockedExchange ((gint32*)(orig_code + 2), (guint)addr - ((guint)orig_code + 1) - 5);
86 #ifdef HAVE_VALGRIND_MEMCHECK_H
87 /* Tell valgrind to recompile the patched code */
88 //VALGRIND_DISCARD_TRANSLATIONS (code + 2, code + 6);
91 } else if (code [1] == 0xe9) {
92 /* A PLT entry: jmp <DISP> */
94 InterlockedExchange ((gint32*)(orig_code + 2), (guint)addr - ((guint)orig_code + 1) - 5);
96 printf ("Invalid trampoline sequence: %x %x %x %x %x %x %x\n", code [0], code [1], code [2], code [3],
97 code [4], code [5], code [6]);
98 g_assert_not_reached ();
103 mono_arch_patch_plt_entry (guint8 *code, guint8 *addr)
105 /* A PLT entry: jmp <DISP> */
106 g_assert (code [0] == 0xe9);
108 if (!mono_running_on_valgrind ())
109 InterlockedExchange ((gint32*)(code + 1), (guint)addr - (guint)code - 5);
113 mono_arch_nullify_class_init_trampoline (guint8 *code, gssize *regs)
116 gboolean can_write = mono_breakpoint_clean_code (NULL, code, 6, buf, sizeof (buf));
122 if (code [0] == 0xe8) {
123 if (!mono_running_on_valgrind ()) {
126 * Thread safe code patching using the algorithm from the paper
127 * 'Practicing JUDO: Java Under Dynamic Optimizations'
130 * First atomically change the the first 2 bytes of the call to a
134 InterlockedExchange ((gint32*)code, ops);
136 /* Then change the other bytes to a nop */
141 /* Then atomically change the first 4 bytes to a nop as well */
143 InterlockedExchange ((gint32*)code, ops);
144 #ifdef HAVE_VALGRIND_MEMCHECK_H
145 /* FIXME: the calltree skin trips on the self modifying code above */
147 /* Tell valgrind to recompile the patched code */
148 //VALGRIND_DISCARD_TRANSLATIONS (code, code + 8);
151 } else if (code [0] == 0x90 || code [0] == 0xeb) {
152 /* Already changed by another thread */
154 } else if ((code [-1] == 0xff) && (x86_modrm_reg (code [0]) == 0x2)) {
155 /* call *<OFFSET>(<REG>) -> Call made from AOT code */
156 gpointer *vtable_slot;
158 vtable_slot = mono_arch_get_vcall_slot_addr (code + 5, (gpointer*)regs);
159 g_assert (vtable_slot);
161 *vtable_slot = nullified_class_init_trampoline;
163 printf ("Invalid trampoline sequence: %x %x %x %x %x %x %x\n", code [0], code [1], code [2], code [3],
164 code [4], code [5], code [6]);
165 g_assert_not_reached ();
170 mono_arch_nullify_plt_entry (guint8 *code)
172 if (!mono_running_on_valgrind ()) {
176 InterlockedExchange ((gint32*)code, ops);
178 /* Then change the other bytes to a nop */
183 /* Change the first byte to a nop */
185 InterlockedExchange ((gint32*)code, ops);
190 mono_arch_create_trampoline_code (MonoTrampolineType tramp_type)
192 guint8 *buf, *code, *tramp;
193 int pushed_args, pushed_args_caller_saved;
195 code = buf = mono_global_codeman_reserve (256);
197 /* Note that there is a single argument to the trampoline
198 * and it is stored at: esp + pushed_args * sizeof (gpointer)
199 * the ret address is at: esp + (pushed_args + 1) * sizeof (gpointer)
202 /* Put all registers into an array on the stack
203 * If this code is changed, make sure to update the offset value in
204 * mono_arch_find_this_argument () in mini-x86.c.
206 x86_push_reg (buf, X86_EDI);
207 x86_push_reg (buf, X86_ESI);
208 x86_push_reg (buf, X86_EBP);
209 x86_push_reg (buf, X86_ESP);
210 x86_push_reg (buf, X86_EBX);
211 x86_push_reg (buf, X86_EDX);
212 x86_push_reg (buf, X86_ECX);
213 x86_push_reg (buf, X86_EAX);
215 pushed_args_caller_saved = pushed_args = 8;
217 /* Align stack on apple */
218 x86_alu_reg_imm (buf, X86_SUB, X86_ESP, 4);
224 /* save the IP (caller ip) */
225 if (tramp_type == MONO_TRAMPOLINE_JUMP)
226 x86_push_imm (buf, 0);
228 x86_push_membase (buf, X86_ESP, (pushed_args + 1) * sizeof (gpointer));
232 x86_push_reg (buf, X86_EBP);
233 x86_push_reg (buf, X86_ESI);
234 x86_push_reg (buf, X86_EDI);
235 x86_push_reg (buf, X86_EBX);
240 x86_push_reg (buf, X86_ESP);
241 /* Adjust ESP so it points to the previous frame */
242 x86_alu_membase_imm (buf, X86_ADD, X86_ESP, 0, (pushed_args + 2) * 4);
246 /* save method info */
247 if ((tramp_type == MONO_TRAMPOLINE_JIT) || (tramp_type == MONO_TRAMPOLINE_JUMP))
248 x86_push_membase (buf, X86_ESP, pushed_args * sizeof (gpointer));
250 x86_push_imm (buf, 0);
254 /* On apple, the stack is correctly aligned to 16 bytes because pushed_args is
255 * 16 and there is the extra trampoline arg + the return ip pushed by call
256 * FIXME: Note that if an exception happens while some args are pushed
257 * on the stack, the stack will be misaligned.
259 g_assert (pushed_args == 16);
261 /* get the address of lmf for the current thread */
262 x86_call_code (buf, mono_get_lmf_addr);
264 x86_push_reg (buf, X86_EAX);
265 /* push *lfm (previous_lmf) */
266 x86_push_membase (buf, X86_EAX, 0);
267 /* Signal to mono_arch_find_jit_info () that this is a trampoline frame */
268 x86_alu_membase_imm (buf, X86_ADD, X86_ESP, 0, 1);
270 x86_mov_membase_reg (buf, X86_EAX, 0, X86_ESP, 4);
275 /* starting the call sequence */
277 /* FIXME: Push the trampoline address */
278 x86_push_imm (buf, 0);
282 /* push the method info */
283 x86_push_membase (buf, X86_ESP, pushed_args * sizeof (gpointer));
287 /* push the return address onto the stack */
288 if (tramp_type == MONO_TRAMPOLINE_JUMP)
289 x86_push_imm (buf, 0);
291 x86_push_membase (buf, X86_ESP, (pushed_args + 1) * sizeof (gpointer));
293 /* push the address of the register array */
294 x86_lea_membase (buf, X86_EAX, X86_ESP, (pushed_args - 8) * sizeof (gpointer));
295 x86_push_reg (buf, X86_EAX);
300 /* check the stack is aligned after the ret ip is pushed */
301 /*x86_mov_reg_reg (buf, X86_EDX, X86_ESP, 4);
302 x86_alu_reg_imm (buf, X86_AND, X86_EDX, 15);
303 x86_alu_reg_imm (buf, X86_CMP, X86_EDX, 0);
304 x86_branch_disp (buf, X86_CC_Z, 3, FALSE);
305 x86_breakpoint (buf);*/
308 tramp = (guint8*)mono_get_trampoline_func (tramp_type);
309 x86_call_code (buf, tramp);
311 x86_alu_reg_imm (buf, X86_ADD, X86_ESP, 4*4);
315 /* Check for thread interruption */
316 /* This is not perf critical code so no need to check the interrupt flag */
317 x86_push_reg (buf, X86_EAX);
318 x86_call_code (buf, (guint8*)mono_thread_force_interruption_checkpoint);
319 x86_pop_reg (buf, X86_EAX);
323 /* ebx = previous_lmf */
324 x86_pop_reg (buf, X86_EBX);
326 x86_alu_reg_imm (buf, X86_SUB, X86_EBX, 1);
329 x86_pop_reg (buf, X86_EDI);
332 /* *(lmf) = previous_lmf */
333 x86_mov_membase_reg (buf, X86_EDI, 0, X86_EBX, 4);
335 /* discard method info */
336 x86_pop_reg (buf, X86_ESI);
340 x86_pop_reg (buf, X86_ESI);
343 /* restore caller saved regs */
344 x86_pop_reg (buf, X86_EBX);
345 x86_pop_reg (buf, X86_EDI);
346 x86_pop_reg (buf, X86_ESI);
347 x86_pop_reg (buf, X86_EBP);
351 /* discard save IP */
352 x86_alu_reg_imm (buf, X86_ADD, X86_ESP, 4);
355 /* restore LMF end */
357 if (!MONO_TRAMPOLINE_TYPE_MUST_RETURN (tramp_type)) {
359 * Overwrite the method ptr with the address we need to jump to,
362 x86_mov_membase_reg (buf, X86_ESP, pushed_args * sizeof (gpointer), X86_EAX, 4);
365 /* Restore caller saved registers */
366 x86_mov_reg_membase (buf, X86_ECX, X86_ESP, (pushed_args - pushed_args_caller_saved + X86_ECX) * 4, 4);
367 x86_mov_reg_membase (buf, X86_EDX, X86_ESP, (pushed_args - pushed_args_caller_saved + X86_EDX) * 4, 4);
368 if ((tramp_type == MONO_TRAMPOLINE_RESTORE_STACK_PROT) || (tramp_type == MONO_TRAMPOLINE_AOT_PLT))
369 x86_mov_reg_membase (buf, X86_EAX, X86_ESP, (pushed_args - pushed_args_caller_saved + X86_EAX) * 4, 4);
371 if (!MONO_TRAMPOLINE_TYPE_MUST_RETURN (tramp_type)) {
372 /* Pop saved reg array + stack align */
373 x86_alu_reg_imm (buf, X86_ADD, X86_ESP, 9 * 4);
375 g_assert (pushed_args == 0);
377 /* Pop saved reg array + stack align + method ptr */
378 x86_alu_reg_imm (buf, X86_ADD, X86_ESP, 10 * 4);
381 /* We've popped one more stack item than we've pushed (the
382 method ptr argument), so we must end up at -1. */
383 g_assert (pushed_args == -1);
388 g_assert ((buf - code) <= 256);
390 if (tramp_type == MONO_TRAMPOLINE_CLASS_INIT) {
391 /* Initialize the nullified class init trampoline used in the AOT case */
392 nullified_class_init_trampoline = buf = mono_global_codeman_reserve (16);
399 #define TRAMPOLINE_SIZE 10
402 mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len)
404 guint8 *code, *buf, *tramp;
406 tramp = mono_get_trampoline_code (tramp_type);
408 mono_domain_lock (domain);
409 code = buf = mono_code_manager_reserve_align (domain->code_mp, TRAMPOLINE_SIZE, 4);
410 mono_domain_unlock (domain);
412 x86_push_imm (buf, arg1);
413 x86_jump_code (buf, tramp);
414 g_assert ((buf - code) <= TRAMPOLINE_SIZE);
416 mono_arch_flush_icache (code, buf - code);
419 *code_len = buf - code;
425 mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot)
429 guint8 **rgctx_null_jumps;
435 mrgctx = MONO_RGCTX_SLOT_IS_MRGCTX (slot);
436 index = MONO_RGCTX_SLOT_INDEX (slot);
438 index += sizeof (MonoMethodRuntimeGenericContext) / sizeof (gpointer);
439 for (depth = 0; ; ++depth) {
440 int size = mono_class_rgctx_get_array_size (depth, mrgctx);
442 if (index < size - 1)
447 tramp_size = 36 + 6 * depth;
449 code = buf = mono_global_codeman_reserve (tramp_size);
451 rgctx_null_jumps = g_malloc (sizeof (guint8*) * (depth + 2));
453 /* load vtable/mrgctx ptr */
454 x86_mov_reg_membase (buf, X86_EAX, X86_ESP, 4, 4);
456 /* load rgctx ptr from vtable */
457 x86_mov_reg_membase (buf, X86_EAX, X86_EAX, G_STRUCT_OFFSET (MonoVTable, runtime_generic_context), 4);
458 /* is the rgctx ptr null? */
459 x86_test_reg_reg (buf, X86_EAX, X86_EAX);
460 /* if yes, jump to actual trampoline */
461 rgctx_null_jumps [0] = buf;
462 x86_branch8 (buf, X86_CC_Z, -1, 1);
465 for (i = 0; i < depth; ++i) {
466 /* load ptr to next array */
467 if (mrgctx && i == 0)
468 x86_mov_reg_membase (buf, X86_EAX, X86_EAX, sizeof (MonoMethodRuntimeGenericContext), 4);
470 x86_mov_reg_membase (buf, X86_EAX, X86_EAX, 0, 4);
471 /* is the ptr null? */
472 x86_test_reg_reg (buf, X86_EAX, X86_EAX);
473 /* if yes, jump to actual trampoline */
474 rgctx_null_jumps [i + 1] = buf;
475 x86_branch8 (buf, X86_CC_Z, -1, 1);
479 x86_mov_reg_membase (buf, X86_EAX, X86_EAX, sizeof (gpointer) * (index + 1), 4);
480 /* is the slot null? */
481 x86_test_reg_reg (buf, X86_EAX, X86_EAX);
482 /* if yes, jump to actual trampoline */
483 rgctx_null_jumps [depth + 1] = buf;
484 x86_branch8 (buf, X86_CC_Z, -1, 1);
485 /* otherwise return */
488 for (i = mrgctx ? 1 : 0; i <= depth + 1; ++i)
489 x86_patch (rgctx_null_jumps [i], buf);
491 g_free (rgctx_null_jumps);
493 x86_mov_reg_membase (buf, MONO_ARCH_VTABLE_REG, X86_ESP, 4, 4);
495 tramp = mono_arch_create_specific_trampoline (GUINT_TO_POINTER (slot), MONO_TRAMPOLINE_RGCTX_LAZY_FETCH, mono_get_root_domain (), NULL);
497 /* jump to the actual trampoline */
498 x86_jump_code (buf, tramp);
500 mono_arch_flush_icache (code, buf - code);
502 g_assert (buf - code <= tramp_size);
508 mono_arch_create_generic_class_init_trampoline (void)
512 static int byte_offset = -1;
513 static guint8 bitmask;
519 code = buf = mono_global_codeman_reserve (tramp_size);
522 mono_marshal_find_bitfield_offset (MonoVTable, initialized, &byte_offset, &bitmask);
524 x86_test_membase_imm (code, MONO_ARCH_VTABLE_REG, byte_offset, bitmask);
526 x86_branch8 (code, X86_CC_Z, -1, 1);
530 x86_patch (jump, code);
532 /* Push the vtable so the stack is the same as in a specific trampoline */
533 x86_push_reg (code, MONO_ARCH_VTABLE_REG);
535 tramp = mono_get_trampoline_code (MONO_TRAMPOLINE_GENERIC_CLASS_INIT);
537 /* jump to the actual trampoline */
538 x86_jump_code (code, tramp);
540 mono_arch_flush_icache (code, code - buf);
542 g_assert (code - buf <= tramp_size);
547 #ifdef MONO_ARCH_MONITOR_OBJECT_REG
549 * The code produced by this trampoline is equivalent to this:
552 * if (obj->synchronisation) {
553 * if (obj->synchronisation->owner == 0) {
554 * if (cmpxch (&obj->synchronisation->owner, TID, 0) == 0)
557 * if (obj->synchronisation->owner == TID) {
558 * ++obj->synchronisation->nest;
563 * return full_monitor_enter ();
567 mono_arch_create_monitor_enter_trampoline (void)
572 return mono_arch_create_monitor_enter_trampoline_full (&code_size, &ji, FALSE);
576 mono_arch_create_monitor_enter_trampoline_full (guint32 *code_size, MonoJumpInfo **ji, gboolean aot)
578 guint8 *tramp = mono_get_trampoline_code (MONO_TRAMPOLINE_MONITOR_ENTER);
580 guint8 *jump_obj_null, *jump_sync_null, *jump_other_owner, *jump_cmpxchg_failed, *jump_tid;
582 int owner_offset, nest_offset, dummy;
584 g_assert (MONO_ARCH_MONITOR_OBJECT_REG == X86_EAX);
586 mono_monitor_threads_sync_members_offset (&owner_offset, &nest_offset, &dummy);
587 g_assert (MONO_THREADS_SYNC_MEMBER_SIZE (owner_offset) == sizeof (gpointer));
588 g_assert (MONO_THREADS_SYNC_MEMBER_SIZE (nest_offset) == sizeof (guint32));
589 owner_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (owner_offset);
590 nest_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (nest_offset);
594 code = buf = mono_global_codeman_reserve (tramp_size);
596 if (mono_thread_get_tls_offset () != -1) {
597 /* MonoObject* obj is in EAX */
599 x86_test_reg_reg (buf, X86_EAX, X86_EAX);
600 /* if yes, jump to actual trampoline */
602 x86_branch8 (buf, X86_CC_Z, -1, 1);
604 /* load obj->synchronization to ECX */
605 x86_mov_reg_membase (buf, X86_ECX, X86_EAX, G_STRUCT_OFFSET (MonoObject, synchronisation), 4);
606 /* is synchronization null? */
607 x86_test_reg_reg (buf, X86_ECX, X86_ECX);
608 /* if yes, jump to actual trampoline */
609 jump_sync_null = buf;
610 x86_branch8 (buf, X86_CC_Z, -1, 1);
612 /* load MonoThread* into EDX */
613 buf = mono_x86_emit_tls_get (buf, X86_EDX, mono_thread_get_tls_offset ());
614 /* load TID into EDX */
615 x86_mov_reg_membase (buf, X86_EDX, X86_EDX, G_STRUCT_OFFSET (MonoThread, tid), 4);
617 /* is synchronization->owner null? */
618 x86_alu_membase_imm (buf, X86_CMP, X86_ECX, owner_offset, 0);
619 /* if not, jump to next case */
621 x86_branch8 (buf, X86_CC_NZ, -1, 1);
623 /* if yes, try a compare-exchange with the TID */
624 /* free up register EAX, needed for the zero */
625 x86_push_reg (buf, X86_EAX);
627 x86_alu_reg_reg (buf, X86_XOR, X86_EAX, X86_EAX);
628 /* compare and exchange */
629 x86_prefix (buf, X86_LOCK_PREFIX);
630 x86_cmpxchg_membase_reg (buf, X86_ECX, owner_offset, X86_EDX);
631 /* if not successful, jump to actual trampoline */
632 jump_cmpxchg_failed = buf;
633 x86_branch8 (buf, X86_CC_NZ, -1, 1);
634 /* if successful, pop and return */
635 x86_pop_reg (buf, X86_EAX);
638 /* next case: synchronization->owner is not null */
639 x86_patch (jump_tid, buf);
640 /* is synchronization->owner == TID? */
641 x86_alu_membase_reg (buf, X86_CMP, X86_ECX, owner_offset, X86_EDX);
642 /* if not, jump to actual trampoline */
643 jump_other_owner = buf;
644 x86_branch8 (buf, X86_CC_NZ, -1, 1);
645 /* if yes, increment nest */
646 x86_inc_membase (buf, X86_ECX, nest_offset);
651 x86_patch (jump_obj_null, buf);
652 x86_patch (jump_sync_null, buf);
653 x86_patch (jump_other_owner, buf);
654 x86_push_reg (buf, X86_EAX);
655 /* jump to the actual trampoline */
656 x86_patch (jump_cmpxchg_failed, buf);
657 x86_jump_code (buf, tramp);
659 /* push obj and jump to the actual trampoline */
660 x86_push_reg (buf, X86_EAX);
661 x86_jump_code (buf, tramp);
664 mono_arch_flush_icache (buf, buf - code);
665 g_assert (buf - code <= tramp_size);
671 mono_arch_create_monitor_exit_trampoline (void)
676 return mono_arch_create_monitor_exit_trampoline_full (&code_size, &ji, FALSE);
680 mono_arch_create_monitor_exit_trampoline_full (guint32 *code_size, MonoJumpInfo **ji, gboolean aot)
682 guint8 *tramp = mono_get_trampoline_code (MONO_TRAMPOLINE_MONITOR_EXIT);
684 guint8 *jump_obj_null, *jump_have_waiters;
687 int owner_offset, nest_offset, entry_count_offset;
689 g_assert (MONO_ARCH_MONITOR_OBJECT_REG == X86_EAX);
691 mono_monitor_threads_sync_members_offset (&owner_offset, &nest_offset, &entry_count_offset);
692 g_assert (MONO_THREADS_SYNC_MEMBER_SIZE (owner_offset) == sizeof (gpointer));
693 g_assert (MONO_THREADS_SYNC_MEMBER_SIZE (nest_offset) == sizeof (guint32));
694 g_assert (MONO_THREADS_SYNC_MEMBER_SIZE (entry_count_offset) == sizeof (gint32));
695 owner_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (owner_offset);
696 nest_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (nest_offset);
697 entry_count_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (entry_count_offset);
701 code = buf = mono_global_codeman_reserve (tramp_size);
703 if (mono_thread_get_tls_offset () != -1) {
704 /* MonoObject* obj is in EAX */
706 x86_test_reg_reg (buf, X86_EAX, X86_EAX);
707 /* if yes, jump to actual trampoline */
709 x86_branch8 (buf, X86_CC_Z, -1, 1);
711 /* load obj->synchronization to ECX */
712 x86_mov_reg_membase (buf, X86_ECX, X86_EAX, G_STRUCT_OFFSET (MonoObject, synchronisation), 4);
713 /* is synchronization null? */
714 x86_test_reg_reg (buf, X86_ECX, X86_ECX);
715 /* if not, jump to next case */
717 x86_branch8 (buf, X86_CC_NZ, -1, 1);
718 /* if yes, just return */
721 /* next case: synchronization is not null */
722 x86_patch (jump_next, buf);
723 /* load MonoThread* into EDX */
724 buf = mono_x86_emit_tls_get (buf, X86_EDX, mono_thread_get_tls_offset ());
725 /* load TID into EDX */
726 x86_mov_reg_membase (buf, X86_EDX, X86_EDX, G_STRUCT_OFFSET (MonoThread, tid), 4);
727 /* is synchronization->owner == TID */
728 x86_alu_membase_reg (buf, X86_CMP, X86_ECX, owner_offset, X86_EDX);
729 /* if yes, jump to next case */
731 x86_branch8 (buf, X86_CC_Z, -1, 1);
732 /* if not, just return */
735 /* next case: synchronization->owner == TID */
736 x86_patch (jump_next, buf);
737 /* is synchronization->nest == 1 */
738 x86_alu_membase_imm (buf, X86_CMP, X86_ECX, nest_offset, 1);
739 /* if not, jump to next case */
741 x86_branch8 (buf, X86_CC_NZ, -1, 1);
742 /* if yes, is synchronization->entry_count zero? */
743 x86_alu_membase_imm (buf, X86_CMP, X86_ECX, entry_count_offset, 0);
744 /* if not, jump to actual trampoline */
745 jump_have_waiters = buf;
746 x86_branch8 (buf, X86_CC_NZ, -1 , 1);
747 /* if yes, set synchronization->owner to null and return */
748 x86_mov_membase_imm (buf, X86_ECX, owner_offset, 0, 4);
751 /* next case: synchronization->nest is not 1 */
752 x86_patch (jump_next, buf);
753 /* decrease synchronization->nest and return */
754 x86_dec_membase (buf, X86_ECX, nest_offset);
757 /* push obj and jump to the actual trampoline */
758 x86_patch (jump_obj_null, buf);
759 x86_patch (jump_have_waiters, buf);
760 x86_push_reg (buf, X86_EAX);
761 x86_jump_code (buf, tramp);
763 /* push obj and jump to the actual trampoline */
764 x86_push_reg (buf, X86_EAX);
765 x86_jump_code (buf, tramp);
768 mono_arch_flush_icache (buf, buf - code);
769 g_assert (buf - code <= tramp_size);
775 mono_arch_create_monitor_enter_trampoline (void)
777 g_assert_not_reached ();
782 mono_arch_create_monitor_exit_trampoline (void)
784 g_assert_not_reached ();
790 mono_arch_invalidate_method (MonoJitInfo *ji, void *func, gpointer func_arg)
792 /* FIXME: This is not thread safe */
793 guint8 *code = ji->code_start;
795 x86_push_imm (code, func_arg);
796 x86_call_code (code, (guint8*)func);