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 start = code = mono_domain_code_reserve (domain, 16);
53 x86_alu_membase_imm (code, X86_ADD, X86_ESP, this_pos, sizeof (MonoObject));
54 x86_jump_code (code, addr);
55 g_assert ((code - start) < 16);
61 mono_arch_patch_callsite (guint8 *method_start, guint8 *orig_code, guint8 *addr)
65 gboolean can_write = mono_breakpoint_clean_code (method_start, orig_code, 8, buf, sizeof (buf));
68 if (mono_running_on_valgrind ())
71 /* go to the start of the call instruction
73 * address_byte = (m << 6) | (o << 3) | reg
74 * call opcode: 0xff address_byte displacement
80 if ((code [1] == 0xe8)) {
82 InterlockedExchange ((gint32*)(orig_code + 2), (guint)addr - ((guint)orig_code + 1) - 5);
84 #ifdef HAVE_VALGRIND_MEMCHECK_H
85 /* Tell valgrind to recompile the patched code */
86 //VALGRIND_DISCARD_TRANSLATIONS (code + 2, code + 6);
89 } else if (code [1] == 0xe9) {
90 /* A PLT entry: jmp <DISP> */
92 InterlockedExchange ((gint32*)(orig_code + 2), (guint)addr - ((guint)orig_code + 1) - 5);
94 printf ("Invalid trampoline sequence: %x %x %x %x %x %x %x\n", code [0], code [1], code [2], code [3],
95 code [4], code [5], code [6]);
96 g_assert_not_reached ();
101 mono_arch_patch_plt_entry (guint8 *code, guint8 *addr)
103 /* A PLT entry: jmp <DISP> */
104 g_assert (code [0] == 0xe9);
106 if (!mono_running_on_valgrind ())
107 InterlockedExchange ((gint32*)(code + 1), (guint)addr - (guint)code - 5);
111 mono_arch_nullify_class_init_trampoline (guint8 *code, gssize *regs)
114 gboolean can_write = mono_breakpoint_clean_code (NULL, code, 6, buf, sizeof (buf));
120 if (code [0] == 0xe8) {
121 if (!mono_running_on_valgrind ()) {
124 * Thread safe code patching using the algorithm from the paper
125 * 'Practicing JUDO: Java Under Dynamic Optimizations'
128 * First atomically change the the first 2 bytes of the call to a
132 InterlockedExchange ((gint32*)code, ops);
134 /* Then change the other bytes to a nop */
139 /* Then atomically change the first 4 bytes to a nop as well */
141 InterlockedExchange ((gint32*)code, ops);
142 #ifdef HAVE_VALGRIND_MEMCHECK_H
143 /* FIXME: the calltree skin trips on the self modifying code above */
145 /* Tell valgrind to recompile the patched code */
146 //VALGRIND_DISCARD_TRANSLATIONS (code, code + 8);
149 } else if (code [0] == 0x90 || code [0] == 0xeb) {
150 /* Already changed by another thread */
152 } else if ((code [-1] == 0xff) && (x86_modrm_reg (code [0]) == 0x2)) {
153 /* call *<OFFSET>(<REG>) -> Call made from AOT code */
154 gpointer *vtable_slot;
156 vtable_slot = mono_arch_get_vcall_slot_addr (code + 5, (gpointer*)regs);
157 g_assert (vtable_slot);
159 *vtable_slot = nullified_class_init_trampoline;
161 printf ("Invalid trampoline sequence: %x %x %x %x %x %x %x\n", code [0], code [1], code [2], code [3],
162 code [4], code [5], code [6]);
163 g_assert_not_reached ();
168 mono_arch_nullify_plt_entry (guint8 *code)
170 if (!mono_running_on_valgrind ()) {
174 InterlockedExchange ((gint32*)code, ops);
176 /* Then change the other bytes to a nop */
181 /* Change the first byte to a nop */
183 InterlockedExchange ((gint32*)code, ops);
188 mono_arch_create_trampoline_code (MonoTrampolineType tramp_type)
190 guint8 *buf, *code, *tramp;
191 int pushed_args, pushed_args_caller_saved;
193 code = buf = mono_global_codeman_reserve (256);
195 /* Note that there is a single argument to the trampoline
196 * and it is stored at: esp + pushed_args * sizeof (gpointer)
197 * the ret address is at: esp + (pushed_args + 1) * sizeof (gpointer)
200 /* Put all registers into an array on the stack
201 * If this code is changed, make sure to update the offset value in
202 * mono_arch_find_this_argument () in mini-x86.c.
204 x86_push_reg (buf, X86_EDI);
205 x86_push_reg (buf, X86_ESI);
206 x86_push_reg (buf, X86_EBP);
207 x86_push_reg (buf, X86_ESP);
208 x86_push_reg (buf, X86_EBX);
209 x86_push_reg (buf, X86_EDX);
210 x86_push_reg (buf, X86_ECX);
211 x86_push_reg (buf, X86_EAX);
213 pushed_args_caller_saved = pushed_args = 8;
215 /* Align stack on apple */
216 x86_alu_reg_imm (buf, X86_SUB, X86_ESP, 4);
222 /* save the IP (caller ip) */
223 if (tramp_type == MONO_TRAMPOLINE_JUMP)
224 x86_push_imm (buf, 0);
226 x86_push_membase (buf, X86_ESP, (pushed_args + 1) * sizeof (gpointer));
230 x86_push_reg (buf, X86_EBP);
231 x86_push_reg (buf, X86_ESI);
232 x86_push_reg (buf, X86_EDI);
233 x86_push_reg (buf, X86_EBX);
238 x86_push_reg (buf, X86_ESP);
239 /* Adjust ESP so it points to the previous frame */
240 x86_alu_membase_imm (buf, X86_ADD, X86_ESP, 0, (pushed_args + 2) * 4);
244 /* save method info */
245 if ((tramp_type == MONO_TRAMPOLINE_JIT) || (tramp_type == MONO_TRAMPOLINE_JUMP))
246 x86_push_membase (buf, X86_ESP, pushed_args * sizeof (gpointer));
248 x86_push_imm (buf, 0);
252 /* On apple, the stack is correctly aligned to 16 bytes because pushed_args is
253 * 16 and there is the extra trampoline arg + the return ip pushed by call
254 * FIXME: Note that if an exception happens while some args are pushed
255 * on the stack, the stack will be misaligned.
257 g_assert (pushed_args == 16);
259 /* get the address of lmf for the current thread */
260 x86_call_code (buf, mono_get_lmf_addr);
262 x86_push_reg (buf, X86_EAX);
263 /* push *lfm (previous_lmf) */
264 x86_push_membase (buf, X86_EAX, 0);
265 /* Signal to mono_arch_find_jit_info () that this is a trampoline frame */
266 x86_alu_membase_imm (buf, X86_ADD, X86_ESP, 0, 1);
268 x86_mov_membase_reg (buf, X86_EAX, 0, X86_ESP, 4);
273 /* starting the call sequence */
275 /* FIXME: Push the trampoline address */
276 x86_push_imm (buf, 0);
280 /* push the method info */
281 x86_push_membase (buf, X86_ESP, pushed_args * sizeof (gpointer));
285 /* push the return address onto the stack */
286 if (tramp_type == MONO_TRAMPOLINE_JUMP)
287 x86_push_imm (buf, 0);
289 x86_push_membase (buf, X86_ESP, (pushed_args + 1) * sizeof (gpointer));
291 /* push the address of the register array */
292 x86_lea_membase (buf, X86_EAX, X86_ESP, (pushed_args - 8) * sizeof (gpointer));
293 x86_push_reg (buf, X86_EAX);
298 /* check the stack is aligned after the ret ip is pushed */
299 /*x86_mov_reg_reg (buf, X86_EDX, X86_ESP, 4);
300 x86_alu_reg_imm (buf, X86_AND, X86_EDX, 15);
301 x86_alu_reg_imm (buf, X86_CMP, X86_EDX, 0);
302 x86_branch_disp (buf, X86_CC_Z, 3, FALSE);
303 x86_breakpoint (buf);*/
306 tramp = (guint8*)mono_get_trampoline_func (tramp_type);
307 x86_call_code (buf, tramp);
309 x86_alu_reg_imm (buf, X86_ADD, X86_ESP, 4*4);
313 /* Check for thread interruption */
314 /* This is not perf critical code so no need to check the interrupt flag */
315 x86_push_reg (buf, X86_EAX);
316 x86_call_code (buf, (guint8*)mono_thread_force_interruption_checkpoint);
317 x86_pop_reg (buf, X86_EAX);
321 /* ebx = previous_lmf */
322 x86_pop_reg (buf, X86_EBX);
324 x86_alu_reg_imm (buf, X86_SUB, X86_EBX, 1);
327 x86_pop_reg (buf, X86_EDI);
330 /* *(lmf) = previous_lmf */
331 x86_mov_membase_reg (buf, X86_EDI, 0, X86_EBX, 4);
333 /* discard method info */
334 x86_pop_reg (buf, X86_ESI);
338 x86_pop_reg (buf, X86_ESI);
341 /* restore caller saved regs */
342 x86_pop_reg (buf, X86_EBX);
343 x86_pop_reg (buf, X86_EDI);
344 x86_pop_reg (buf, X86_ESI);
345 x86_pop_reg (buf, X86_EBP);
349 /* discard save IP */
350 x86_alu_reg_imm (buf, X86_ADD, X86_ESP, 4);
353 /* restore LMF end */
355 if (!MONO_TRAMPOLINE_TYPE_MUST_RETURN (tramp_type)) {
357 * Overwrite the method ptr with the address we need to jump to,
360 x86_mov_membase_reg (buf, X86_ESP, pushed_args * sizeof (gpointer), X86_EAX, 4);
363 /* Restore caller saved registers */
364 x86_mov_reg_membase (buf, X86_ECX, X86_ESP, (pushed_args - pushed_args_caller_saved + X86_ECX) * 4, 4);
365 x86_mov_reg_membase (buf, X86_EDX, X86_ESP, (pushed_args - pushed_args_caller_saved + X86_EDX) * 4, 4);
366 if ((tramp_type == MONO_TRAMPOLINE_RESTORE_STACK_PROT) || (tramp_type == MONO_TRAMPOLINE_AOT_PLT))
367 x86_mov_reg_membase (buf, X86_EAX, X86_ESP, (pushed_args - pushed_args_caller_saved + X86_EAX) * 4, 4);
369 if (!MONO_TRAMPOLINE_TYPE_MUST_RETURN (tramp_type)) {
370 /* Pop saved reg array + stack align */
371 x86_alu_reg_imm (buf, X86_ADD, X86_ESP, 9 * 4);
373 g_assert (pushed_args == 0);
375 /* Pop saved reg array + stack align + method ptr */
376 x86_alu_reg_imm (buf, X86_ADD, X86_ESP, 10 * 4);
379 /* We've popped one more stack item than we've pushed (the
380 method ptr argument), so we must end up at -1. */
381 g_assert (pushed_args == -1);
386 g_assert ((buf - code) <= 256);
388 if (tramp_type == MONO_TRAMPOLINE_CLASS_INIT) {
389 /* Initialize the nullified class init trampoline used in the AOT case */
390 nullified_class_init_trampoline = buf = mono_global_codeman_reserve (16);
397 #define TRAMPOLINE_SIZE 10
400 mono_arch_create_specific_trampoline (gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len)
402 guint8 *code, *buf, *tramp;
404 tramp = mono_get_trampoline_code (tramp_type);
406 code = buf = mono_domain_code_reserve_align (domain, TRAMPOLINE_SIZE, 4);
408 x86_push_imm (buf, arg1);
409 x86_jump_code (buf, tramp);
410 g_assert ((buf - code) <= TRAMPOLINE_SIZE);
412 mono_arch_flush_icache (code, buf - code);
415 *code_len = buf - code;
421 mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot)
425 guint8 **rgctx_null_jumps;
431 mrgctx = MONO_RGCTX_SLOT_IS_MRGCTX (slot);
432 index = MONO_RGCTX_SLOT_INDEX (slot);
434 index += sizeof (MonoMethodRuntimeGenericContext) / sizeof (gpointer);
435 for (depth = 0; ; ++depth) {
436 int size = mono_class_rgctx_get_array_size (depth, mrgctx);
438 if (index < size - 1)
443 tramp_size = 36 + 6 * depth;
445 code = buf = mono_global_codeman_reserve (tramp_size);
447 rgctx_null_jumps = g_malloc (sizeof (guint8*) * (depth + 2));
449 /* load vtable/mrgctx ptr */
450 x86_mov_reg_membase (buf, X86_EAX, X86_ESP, 4, 4);
452 /* load rgctx ptr from vtable */
453 x86_mov_reg_membase (buf, X86_EAX, X86_EAX, G_STRUCT_OFFSET (MonoVTable, runtime_generic_context), 4);
454 /* is the rgctx ptr null? */
455 x86_test_reg_reg (buf, X86_EAX, X86_EAX);
456 /* if yes, jump to actual trampoline */
457 rgctx_null_jumps [0] = buf;
458 x86_branch8 (buf, X86_CC_Z, -1, 1);
461 for (i = 0; i < depth; ++i) {
462 /* load ptr to next array */
463 if (mrgctx && i == 0)
464 x86_mov_reg_membase (buf, X86_EAX, X86_EAX, sizeof (MonoMethodRuntimeGenericContext), 4);
466 x86_mov_reg_membase (buf, X86_EAX, X86_EAX, 0, 4);
467 /* is the ptr null? */
468 x86_test_reg_reg (buf, X86_EAX, X86_EAX);
469 /* if yes, jump to actual trampoline */
470 rgctx_null_jumps [i + 1] = buf;
471 x86_branch8 (buf, X86_CC_Z, -1, 1);
475 x86_mov_reg_membase (buf, X86_EAX, X86_EAX, sizeof (gpointer) * (index + 1), 4);
476 /* is the slot null? */
477 x86_test_reg_reg (buf, X86_EAX, X86_EAX);
478 /* if yes, jump to actual trampoline */
479 rgctx_null_jumps [depth + 1] = buf;
480 x86_branch8 (buf, X86_CC_Z, -1, 1);
481 /* otherwise return */
484 for (i = mrgctx ? 1 : 0; i <= depth + 1; ++i)
485 x86_patch (rgctx_null_jumps [i], buf);
487 g_free (rgctx_null_jumps);
489 x86_mov_reg_membase (buf, MONO_ARCH_VTABLE_REG, X86_ESP, 4, 4);
491 tramp = mono_arch_create_specific_trampoline (GUINT_TO_POINTER (slot), MONO_TRAMPOLINE_RGCTX_LAZY_FETCH, mono_get_root_domain (), NULL);
493 /* jump to the actual trampoline */
494 x86_jump_code (buf, tramp);
496 mono_arch_flush_icache (code, buf - code);
498 g_assert (buf - code <= tramp_size);
504 mono_arch_create_generic_class_init_trampoline (void)
508 static int byte_offset = -1;
509 static guint8 bitmask;
515 code = buf = mono_global_codeman_reserve (tramp_size);
518 mono_marshal_find_bitfield_offset (MonoVTable, initialized, &byte_offset, &bitmask);
520 x86_test_membase_imm (code, MONO_ARCH_VTABLE_REG, byte_offset, bitmask);
522 x86_branch8 (code, X86_CC_Z, -1, 1);
526 x86_patch (jump, code);
528 /* Push the vtable so the stack is the same as in a specific trampoline */
529 x86_push_reg (code, MONO_ARCH_VTABLE_REG);
531 tramp = mono_get_trampoline_code (MONO_TRAMPOLINE_GENERIC_CLASS_INIT);
533 /* jump to the actual trampoline */
534 x86_jump_code (code, tramp);
536 mono_arch_flush_icache (code, code - buf);
538 g_assert (code - buf <= tramp_size);
543 #ifdef MONO_ARCH_MONITOR_OBJECT_REG
545 * The code produced by this trampoline is equivalent to this:
548 * if (obj->synchronisation) {
549 * if (obj->synchronisation->owner == 0) {
550 * if (cmpxch (&obj->synchronisation->owner, TID, 0) == 0)
553 * if (obj->synchronisation->owner == TID) {
554 * ++obj->synchronisation->nest;
559 * return full_monitor_enter ();
563 mono_arch_create_monitor_enter_trampoline (void)
568 return mono_arch_create_monitor_enter_trampoline_full (&code_size, &ji, FALSE);
572 mono_arch_create_monitor_enter_trampoline_full (guint32 *code_size, MonoJumpInfo **ji, gboolean aot)
574 guint8 *tramp = mono_get_trampoline_code (MONO_TRAMPOLINE_MONITOR_ENTER);
576 guint8 *jump_obj_null, *jump_sync_null, *jump_other_owner, *jump_cmpxchg_failed, *jump_tid;
578 int owner_offset, nest_offset, dummy;
580 g_assert (MONO_ARCH_MONITOR_OBJECT_REG == X86_EAX);
582 mono_monitor_threads_sync_members_offset (&owner_offset, &nest_offset, &dummy);
583 g_assert (MONO_THREADS_SYNC_MEMBER_SIZE (owner_offset) == sizeof (gpointer));
584 g_assert (MONO_THREADS_SYNC_MEMBER_SIZE (nest_offset) == sizeof (guint32));
585 owner_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (owner_offset);
586 nest_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (nest_offset);
590 code = buf = mono_global_codeman_reserve (tramp_size);
592 if (mono_thread_get_tls_offset () != -1) {
593 /* MonoObject* obj is in EAX */
595 x86_test_reg_reg (buf, X86_EAX, X86_EAX);
596 /* if yes, jump to actual trampoline */
598 x86_branch8 (buf, X86_CC_Z, -1, 1);
600 /* load obj->synchronization to ECX */
601 x86_mov_reg_membase (buf, X86_ECX, X86_EAX, G_STRUCT_OFFSET (MonoObject, synchronisation), 4);
602 /* is synchronization null? */
603 x86_test_reg_reg (buf, X86_ECX, X86_ECX);
604 /* if yes, jump to actual trampoline */
605 jump_sync_null = buf;
606 x86_branch8 (buf, X86_CC_Z, -1, 1);
608 /* load MonoThread* into EDX */
609 buf = mono_x86_emit_tls_get (buf, X86_EDX, mono_thread_get_tls_offset ());
610 /* load TID into EDX */
611 x86_mov_reg_membase (buf, X86_EDX, X86_EDX, G_STRUCT_OFFSET (MonoThread, tid), 4);
613 /* is synchronization->owner null? */
614 x86_alu_membase_imm (buf, X86_CMP, X86_ECX, owner_offset, 0);
615 /* if not, jump to next case */
617 x86_branch8 (buf, X86_CC_NZ, -1, 1);
619 /* if yes, try a compare-exchange with the TID */
620 /* free up register EAX, needed for the zero */
621 x86_push_reg (buf, X86_EAX);
623 x86_alu_reg_reg (buf, X86_XOR, X86_EAX, X86_EAX);
624 /* compare and exchange */
625 x86_prefix (buf, X86_LOCK_PREFIX);
626 x86_cmpxchg_membase_reg (buf, X86_ECX, owner_offset, X86_EDX);
627 /* if not successful, jump to actual trampoline */
628 jump_cmpxchg_failed = buf;
629 x86_branch8 (buf, X86_CC_NZ, -1, 1);
630 /* if successful, pop and return */
631 x86_pop_reg (buf, X86_EAX);
634 /* next case: synchronization->owner is not null */
635 x86_patch (jump_tid, buf);
636 /* is synchronization->owner == TID? */
637 x86_alu_membase_reg (buf, X86_CMP, X86_ECX, owner_offset, X86_EDX);
638 /* if not, jump to actual trampoline */
639 jump_other_owner = buf;
640 x86_branch8 (buf, X86_CC_NZ, -1, 1);
641 /* if yes, increment nest */
642 x86_inc_membase (buf, X86_ECX, nest_offset);
647 x86_patch (jump_obj_null, buf);
648 x86_patch (jump_sync_null, buf);
649 x86_patch (jump_other_owner, buf);
650 x86_push_reg (buf, X86_EAX);
651 /* jump to the actual trampoline */
652 x86_patch (jump_cmpxchg_failed, buf);
653 x86_jump_code (buf, tramp);
655 /* push obj and jump to the actual trampoline */
656 x86_push_reg (buf, X86_EAX);
657 x86_jump_code (buf, tramp);
660 mono_arch_flush_icache (buf, buf - code);
661 g_assert (buf - code <= tramp_size);
667 mono_arch_create_monitor_exit_trampoline (void)
672 return mono_arch_create_monitor_exit_trampoline_full (&code_size, &ji, FALSE);
676 mono_arch_create_monitor_exit_trampoline_full (guint32 *code_size, MonoJumpInfo **ji, gboolean aot)
678 guint8 *tramp = mono_get_trampoline_code (MONO_TRAMPOLINE_MONITOR_EXIT);
680 guint8 *jump_obj_null, *jump_have_waiters;
683 int owner_offset, nest_offset, entry_count_offset;
685 g_assert (MONO_ARCH_MONITOR_OBJECT_REG == X86_EAX);
687 mono_monitor_threads_sync_members_offset (&owner_offset, &nest_offset, &entry_count_offset);
688 g_assert (MONO_THREADS_SYNC_MEMBER_SIZE (owner_offset) == sizeof (gpointer));
689 g_assert (MONO_THREADS_SYNC_MEMBER_SIZE (nest_offset) == sizeof (guint32));
690 g_assert (MONO_THREADS_SYNC_MEMBER_SIZE (entry_count_offset) == sizeof (gint32));
691 owner_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (owner_offset);
692 nest_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (nest_offset);
693 entry_count_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (entry_count_offset);
697 code = buf = mono_global_codeman_reserve (tramp_size);
699 if (mono_thread_get_tls_offset () != -1) {
700 /* MonoObject* obj is in EAX */
702 x86_test_reg_reg (buf, X86_EAX, X86_EAX);
703 /* if yes, jump to actual trampoline */
705 x86_branch8 (buf, X86_CC_Z, -1, 1);
707 /* load obj->synchronization to ECX */
708 x86_mov_reg_membase (buf, X86_ECX, X86_EAX, G_STRUCT_OFFSET (MonoObject, synchronisation), 4);
709 /* is synchronization null? */
710 x86_test_reg_reg (buf, X86_ECX, X86_ECX);
711 /* if not, jump to next case */
713 x86_branch8 (buf, X86_CC_NZ, -1, 1);
714 /* if yes, just return */
717 /* next case: synchronization is not null */
718 x86_patch (jump_next, buf);
719 /* load MonoThread* into EDX */
720 buf = mono_x86_emit_tls_get (buf, X86_EDX, mono_thread_get_tls_offset ());
721 /* load TID into EDX */
722 x86_mov_reg_membase (buf, X86_EDX, X86_EDX, G_STRUCT_OFFSET (MonoThread, tid), 4);
723 /* is synchronization->owner == TID */
724 x86_alu_membase_reg (buf, X86_CMP, X86_ECX, owner_offset, X86_EDX);
725 /* if yes, jump to next case */
727 x86_branch8 (buf, X86_CC_Z, -1, 1);
728 /* if not, just return */
731 /* next case: synchronization->owner == TID */
732 x86_patch (jump_next, buf);
733 /* is synchronization->nest == 1 */
734 x86_alu_membase_imm (buf, X86_CMP, X86_ECX, nest_offset, 1);
735 /* if not, jump to next case */
737 x86_branch8 (buf, X86_CC_NZ, -1, 1);
738 /* if yes, is synchronization->entry_count zero? */
739 x86_alu_membase_imm (buf, X86_CMP, X86_ECX, entry_count_offset, 0);
740 /* if not, jump to actual trampoline */
741 jump_have_waiters = buf;
742 x86_branch8 (buf, X86_CC_NZ, -1 , 1);
743 /* if yes, set synchronization->owner to null and return */
744 x86_mov_membase_imm (buf, X86_ECX, owner_offset, 0, 4);
747 /* next case: synchronization->nest is not 1 */
748 x86_patch (jump_next, buf);
749 /* decrease synchronization->nest and return */
750 x86_dec_membase (buf, X86_ECX, nest_offset);
753 /* push obj and jump to the actual trampoline */
754 x86_patch (jump_obj_null, buf);
755 x86_patch (jump_have_waiters, buf);
756 x86_push_reg (buf, X86_EAX);
757 x86_jump_code (buf, tramp);
759 /* push obj and jump to the actual trampoline */
760 x86_push_reg (buf, X86_EAX);
761 x86_jump_code (buf, tramp);
764 mono_arch_flush_icache (buf, buf - code);
765 g_assert (buf - code <= tramp_size);
771 mono_arch_create_monitor_enter_trampoline (void)
773 g_assert_not_reached ();
778 mono_arch_create_monitor_exit_trampoline (void)
780 g_assert_not_reached ();
786 mono_arch_invalidate_method (MonoJitInfo *ji, void *func, gpointer func_arg)
788 /* FIXME: This is not thread safe */
789 guint8 *code = ji->code_start;
791 x86_push_imm (code, func_arg);
792 x86_call_code (code, (guint8*)func);