+
+ g_assert (MONO_ARCH_MONITOR_OBJECT_REG == obj_reg);
+#ifdef MONO_ARCH_MONITOR_LOCK_TAKEN_REG
+ g_assert (MONO_ARCH_MONITOR_LOCK_TAKEN_REG == lock_taken_reg);
+#else
+ g_assert (!is_v4);
+#endif
+
+ mono_monitor_threads_sync_members_offset (&status_offset, &nest_offset);
+ g_assert (MONO_THREADS_SYNC_MEMBER_SIZE (status_offset) == sizeof (guint32));
+ g_assert (MONO_THREADS_SYNC_MEMBER_SIZE (nest_offset) == sizeof (guint32));
+ status_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (status_offset);
+ nest_offset = MONO_THREADS_SYNC_MEMBER_OFFSET (nest_offset);
+
+ tramp_size = 160;
+
+ code = buf = mono_global_codeman_reserve (tramp_size);
+
+ unwind_ops = mono_arch_get_cie_program ();
+
+ if (mono_thread_get_tls_offset () != -1) {
+ /* MonoObject* obj is in obj_reg */
+ /* is obj null? */
+ s390_ltgr (code, obj_reg, obj_reg);
+ /* if yes, jump to actual trampoline */
+ s390_jz (code, 0); CODEPTR(code, jump_obj_null);
+
+ if (is_v4) {
+ s390_cli (code, lock_taken_reg, 0, 1);
+ /* if *lock_taken is 1, jump to actual trampoline */
+ s390_je (code, 0); CODEPTR(code, jump_lock_taken_true);
+ }
+
+ /* load obj->synchronization to sync_reg */
+ s390_lg (code, sync_reg, 0, obj_reg, MONO_STRUCT_OFFSET (MonoObject, synchronisation));
+
+ if (mono_gc_is_moving ()) {
+ /*if bit zero is set it's a thin hash*/
+ s390_tmll (code, sync_reg, 1);
+ s390_jo (code, 0); CODEPTR(code, jump_sync_thin_hash);
+
+ /* Clear bits used by the gc */
+ s390_nill (code, sync_reg, ~0x3);
+ }
+
+ /* is synchronization null? */
+ s390_ltgr (code, sync_reg, sync_reg);
+ /* if yes, jump to actual trampoline */
+ s390_jz (code, 0); CODEPTR(code, jump_sync_null);
+
+ /* load MonoInternalThread* into tid_reg */
+ s390_ear (code, s390_r5, 0);
+ s390_sllg(code, s390_r5, s390_r5, 0, 32);
+ s390_ear (code, s390_r5, 1);
+ /* load tid */
+ s390_lg (code, tid_reg, 0, s390_r5, mono_thread_get_tls_offset ());
+ s390_lgf (code, tid_reg, 0, tid_reg, MONO_STRUCT_OFFSET (MonoInternalThread, small_id));
+
+ /* is synchronization->owner free */
+ s390_lgf (code, status_reg, 0, sync_reg, status_offset);
+ s390_nilf (code, status_reg, OWNER_MASK);
+ /* if not, jump to next case */
+ s390_jnz (code, 0); CODEPTR(code, jump_tid);
+
+ /* if yes, try a compare-exchange with the TID */
+ /* Form new status in tid_reg */
+ s390_xr (code, tid_reg, status_reg);
+ /* compare and exchange */
+ s390_cs (code, status_reg, tid_reg, sync_reg, status_offset);
+ s390_jnz (code, 0); CODEPTR(code, jump_cs_failed);
+ /* if successful, return */
+ if (is_v4)
+ s390_mvi (code, lock_taken_reg, 0, 1);
+ s390_br (code, s390_r14);
+
+ /* next case: synchronization->owner is not null */
+ PTRSLOT(code, jump_tid);
+ /* is synchronization->owner == TID? */
+ s390_nilf (code, status_reg, OWNER_MASK);
+ s390_cr (code, status_reg, tid_reg);
+ /* if not, jump to actual trampoline */
+ s390_jnz (code, 0); CODEPTR(code, jump_other_owner);
+ /* if yes, increment nest */
+ s390_lgf (code, s390_r5, 0, sync_reg, nest_offset);
+ s390_ahi (code, s390_r5, 1);
+ s390_st (code, s390_r5, 0, sync_reg, nest_offset);
+ /* return */
+ if (is_v4)
+ s390_mvi (code, lock_taken_reg, 0, 1);
+ s390_br (code, s390_r14);
+
+ PTRSLOT (code, jump_obj_null);
+ if (jump_sync_thin_hash)
+ PTRSLOT (code, jump_sync_thin_hash);
+ PTRSLOT (code, jump_sync_null);
+ PTRSLOT (code, jump_cs_failed);
+ PTRSLOT (code, jump_other_owner);
+ if (is_v4)
+ PTRSLOT (code, jump_lock_taken_true);
+ }
+
+ /* jump to the actual trampoline */
+ if (is_v4)
+ tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_MONITOR_ENTER_V4, mono_get_root_domain (), NULL);
+ else
+ tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_MONITOR_ENTER, mono_get_root_domain (), NULL);
+
+ /* jump to the actual trampoline */
+ S390_SET (code, s390_r1, tramp);
+ s390_br (code, s390_r1);
+
+ mono_arch_flush_icache (code, code - buf);
+ mono_profiler_code_buffer_new (buf, code - buf, MONO_PROFILER_CODE_BUFFER_MONITOR, NULL);
+ g_assert (code - buf <= tramp_size);
+
+ if (info) {
+ if (is_v4)
+ *info = mono_tramp_info_create ("monitor_enter_v4_trampoline", buf, code - buf, ji, unwind_ops);
+ else
+ *info = mono_tramp_info_create ("monitor_enter_trampoline", buf, code - buf, ji, unwind_ops);
+ }
+
+ return buf;
+}
+
+/*========================= End of Function ========================*/
+
+/*------------------------------------------------------------------*/
+/* */
+/* Name - mono_arch_create_monitor_exit_trampoline */
+/* */
+/* Function - */
+/* */
+/*------------------------------------------------------------------*/
+
+gpointer
+mono_arch_create_monitor_exit_trampoline (MonoTrampInfo **info, gboolean aot)
+{
+ guint8 *tramp,
+ *code, *buf;
+ gint16 *jump_obj_null,
+ *jump_have_waiters,
+ *jump_sync_null,
+ *jump_not_owned,
+ *jump_cs_failed,
+ *jump_next,
+ *jump_sync_thin_hash = NULL;
+ int tramp_size,
+ status_offset, nest_offset;