#include <mono/metadata/metadata-internals.h>
#include <mono/metadata/marshal.h>
#include <mono/metadata/gc-internal.h>
-#include <mono/metadata/monitor.h>
#include <mono/metadata/mempool-internals.h>
#include <mono/metadata/mono-endian.h>
#include <mono/metadata/threads-types.h>
/* FIXME: Could this clobber the register needed by get_vcall_slot () ? */
- /* We clobber ECX, since EAX is used as MONO_ARCH_MONITOR_OBJECT_REG */
-#ifdef MONO_ARCH_MONITOR_OBJECT_REG
- g_assert (MONO_ARCH_MONITOR_OBJECT_REG != X86_ECX);
-#ifdef MONO_ARCH_MONITOR_LOCK_TAKEN_REG
- g_assert (MONO_ARCH_MONITOR_LOCK_TAKEN_REG != X86_ECX);
-#endif
-#endif
-
code = buf;
/* Load mscorlib got address */
x86_mov_reg_membase (code, X86_ECX, MONO_ARCH_GOT_REG, sizeof (gpointer), 4);
case MONO_PATCH_INFO_JIT_ICALL_ADDR:
case MONO_PATCH_INFO_ICALL_ADDR:
case MONO_PATCH_INFO_RGCTX_FETCH:
- case MONO_PATCH_INFO_MONITOR_ENTER:
- case MONO_PATCH_INFO_MONITOR_ENTER_V4:
- case MONO_PATCH_INFO_MONITOR_EXIT:
case MONO_PATCH_INFO_LLVM_IMT_TRAMPOLINE:
return TRUE;
default:
encode_patch (acfg, entry->data, p, &p);
break;
}
- case MONO_PATCH_INFO_MONITOR_ENTER:
- case MONO_PATCH_INFO_MONITOR_ENTER_V4:
- case MONO_PATCH_INFO_MONITOR_EXIT:
case MONO_PATCH_INFO_SEQ_POINT_INFO:
break;
case MONO_PATCH_INFO_LLVM_IMT_TRAMPOLINE:
emit_trampoline (acfg, acfg->got_offset, info);
}
-#if defined(MONO_ARCH_MONITOR_OBJECT_REG)
- mono_arch_create_monitor_enter_trampoline (&info, FALSE, TRUE);
- emit_trampoline (acfg, acfg->got_offset, info);
-#if defined(MONO_ARCH_MONITOR_LOCK_TAKEN_REG)
- mono_arch_create_monitor_enter_trampoline (&info, TRUE, TRUE);
- emit_trampoline (acfg, acfg->got_offset, info);
-#endif
- mono_arch_create_monitor_exit_trampoline (&info, TRUE);
- emit_trampoline (acfg, acfg->got_offset, info);
-#endif
-
/* Emit the exception related code pieces */
mono_arch_get_restore_context (&info, TRUE);
emit_trampoline (acfg, acfg->got_offset, info);
#include <mono/metadata/metadata-internals.h>
#include <mono/metadata/marshal.h>
#include <mono/metadata/gc-internal.h>
-#include <mono/metadata/monitor.h>
#include <mono/metadata/threads-types.h>
#include <mono/metadata/mono-endian.h>
#include <mono/utils/mono-logger-internal.h>
ji->data.offset = decode_value (p, &p);
break;
case MONO_PATCH_INFO_INTERRUPTION_REQUEST_FLAG:
- case MONO_PATCH_INFO_MONITOR_ENTER:
- case MONO_PATCH_INFO_MONITOR_ENTER_V4:
- case MONO_PATCH_INFO_MONITOR_EXIT:
case MONO_PATCH_INFO_GC_CARD_TABLE_ADDR:
case MONO_PATCH_INFO_GC_NURSERY_START:
case MONO_PATCH_INFO_JIT_TLS_ID:
g_assert (res == 1);
target = mono_create_specific_trampoline (GUINT_TO_POINTER (slot), MONO_TRAMPOLINE_RGCTX_LAZY_FETCH, mono_get_root_domain (), NULL);
target = mono_create_ftnptr_malloc (target);
- } else if (!strcmp (ji->data.name, "specific_trampoline_monitor_enter")) {
- target = mono_create_specific_trampoline (NULL, MONO_TRAMPOLINE_MONITOR_ENTER, mono_get_root_domain (), NULL);
- target = mono_create_ftnptr_malloc (target);
- } else if (!strcmp (ji->data.name, "specific_trampoline_monitor_enter_v4")) {
- target = mono_create_specific_trampoline (NULL, MONO_TRAMPOLINE_MONITOR_ENTER_V4, mono_get_root_domain (), NULL);
- target = mono_create_ftnptr_malloc (target);
- } else if (!strcmp (ji->data.name, "specific_trampoline_monitor_exit")) {
- target = mono_create_specific_trampoline (NULL, MONO_TRAMPOLINE_MONITOR_EXIT, mono_get_root_domain (), NULL);
- target = mono_create_ftnptr_malloc (target);
} else if (!strcmp (ji->data.name, "mono_thread_get_and_clear_pending_exception")) {
target = mono_thread_get_and_clear_pending_exception;
} else if (!strcmp (ji->data.name, "debugger_agent_single_step_from_context")) {
#include <mono/metadata/security-manager.h>
#include <mono/metadata/threads-types.h>
#include <mono/metadata/security-core-clr.h>
-#include <mono/metadata/monitor.h>
#include <mono/metadata/profiler-private.h>
#include <mono/metadata/profiler.h>
#include <mono/metadata/debug-mono-symfile.h>
/* helper methods signatures */
static MonoMethodSignature *helper_sig_domain_get;
static MonoMethodSignature *helper_sig_rgctx_lazy_fetch_trampoline;
-static MonoMethodSignature *helper_sig_monitor_enter_exit_trampoline;
-static MonoMethodSignature *helper_sig_monitor_enter_exit_trampoline_llvm;
-static MonoMethodSignature *helper_sig_monitor_enter_v4_trampoline_llvm;
/*
* Instruction metadata
{
helper_sig_domain_get = mono_create_icall_signature ("ptr");
helper_sig_rgctx_lazy_fetch_trampoline = mono_create_icall_signature ("ptr ptr");
- helper_sig_monitor_enter_exit_trampoline = mono_create_icall_signature ("void");
- helper_sig_monitor_enter_exit_trampoline_llvm = mono_create_icall_signature ("void object");
- helper_sig_monitor_enter_v4_trampoline_llvm = mono_create_icall_signature ("void object ptr");
}
static MONO_NEVER_INLINE void
return ins;
}
}
- } else if (cmethod->klass == mono_defaults.monitor_class) {
-#if defined(MONO_ARCH_MONITOR_OBJECT_REG)
- if (strcmp (cmethod->name, "Enter") == 0 && fsig->param_count == 1) {
- MonoCallInst *call;
-
- if (COMPILE_LLVM (cfg)) {
- /*
- * Pass the argument normally, the LLVM backend will handle the
- * calling convention problems.
- */
- call = (MonoCallInst*)mono_emit_abs_call (cfg, MONO_PATCH_INFO_MONITOR_ENTER, NULL, helper_sig_monitor_enter_exit_trampoline_llvm, args);
- } else {
- call = (MonoCallInst*)mono_emit_abs_call (cfg, MONO_PATCH_INFO_MONITOR_ENTER,
- NULL, helper_sig_monitor_enter_exit_trampoline, NULL);
- mono_call_inst_add_outarg_reg (cfg, call, args [0]->dreg,
- MONO_ARCH_MONITOR_OBJECT_REG, FALSE);
- }
-
- return (MonoInst*)call;
-#if defined(MONO_ARCH_MONITOR_LOCK_TAKEN_REG)
- } else if (strcmp (cmethod->name, "Enter") == 0 && fsig->param_count == 2) {
- MonoCallInst *call;
-
- if (COMPILE_LLVM (cfg)) {
- /*
- * Pass the argument normally, the LLVM backend will handle the
- * calling convention problems.
- */
- call = (MonoCallInst*)mono_emit_abs_call (cfg, MONO_PATCH_INFO_MONITOR_ENTER_V4, NULL, helper_sig_monitor_enter_v4_trampoline_llvm, args);
- } else {
- call = (MonoCallInst*)mono_emit_abs_call (cfg, MONO_PATCH_INFO_MONITOR_ENTER_V4,
- NULL, helper_sig_monitor_enter_exit_trampoline, NULL);
- mono_call_inst_add_outarg_reg (cfg, call, args [0]->dreg, MONO_ARCH_MONITOR_OBJECT_REG, FALSE);
- mono_call_inst_add_outarg_reg (cfg, call, args [1]->dreg, MONO_ARCH_MONITOR_LOCK_TAKEN_REG, FALSE);
- }
-
- return (MonoInst*)call;
-#endif
- } else if (strcmp (cmethod->name, "Exit") == 0 && fsig->param_count == 1) {
- MonoCallInst *call;
-
- if (COMPILE_LLVM (cfg)) {
- call = (MonoCallInst*)mono_emit_abs_call (cfg, MONO_PATCH_INFO_MONITOR_EXIT, NULL, helper_sig_monitor_enter_exit_trampoline_llvm, args);
- } else {
- call = (MonoCallInst*)mono_emit_abs_call (cfg, MONO_PATCH_INFO_MONITOR_EXIT,
- NULL, helper_sig_monitor_enter_exit_trampoline, NULL);
- mono_call_inst_add_outarg_reg (cfg, call, args [0]->dreg,
- MONO_ARCH_MONITOR_OBJECT_REG, FALSE);
- }
-
- return (MonoInst*)call;
- }
-#endif
} else if (cmethod->klass->image == mono_defaults.corlib &&
(strcmp (cmethod->klass->name_space, "System.Threading") == 0) &&
(strcmp (cmethod->klass->name, "Interlocked") == 0)) {
#define MONO_ARCH_HAVE_GENERALIZED_IMT_THUNK 1
#define MONO_ARCH_HAVE_LIVERANGE_OPS 1
#define MONO_ARCH_HAVE_SIGCTX_TO_MONOCTX 1
-#define MONO_ARCH_MONITOR_OBJECT_REG MONO_AMD64_ARG_REG1
-#define MONO_ARCH_MONITOR_LOCK_TAKEN_REG MONO_AMD64_ARG_REG2
#define MONO_ARCH_HAVE_GET_TRAMPOLINES 1
#define MONO_ARCH_AOT_SUPPORTED 1
case MONO_PATCH_INFO_GC_CARD_TABLE_ADDR:
case MONO_PATCH_INFO_GC_NURSERY_START:
case MONO_PATCH_INFO_JIT_TLS_ID:
- case MONO_PATCH_INFO_MONITOR_ENTER:
- case MONO_PATCH_INFO_MONITOR_ENTER_V4:
- case MONO_PATCH_INFO_MONITOR_EXIT:
case MONO_PATCH_INFO_GOT_OFFSET:
case MONO_PATCH_INFO_GC_SAFE_POINT_FLAG:
return (ji->type << 8);
target = mono_create_rgctx_lazy_fetch_trampoline (slot);
break;
}
- case MONO_PATCH_INFO_MONITOR_ENTER:
- target = mono_create_monitor_enter_trampoline ();
- break;
- case MONO_PATCH_INFO_MONITOR_ENTER_V4:
- target = mono_create_monitor_enter_v4_trampoline ();
- break;
- case MONO_PATCH_INFO_MONITOR_EXIT:
- target = mono_create_monitor_exit_trampoline ();
- break;
#ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
case MONO_PATCH_INFO_SEQ_POINT_INFO:
if (!run_cctors)
#define MONO_ARCH_HAVE_INVALIDATE_METHOD 1
#define MONO_ARCH_HAVE_OP_GENERIC_CLASS_INIT 1
#define MONO_ARCH_HAVE_SETUP_ASYNC_CALLBACK 1
-#define MONO_ARCH_MONITOR_OBJECT_REG s390_r2
-#define MONO_ARCH_LOCK_TAKEN_REG s390_r1
#define S390_STACK_ALIGNMENT 8
#define S390_FIRST_ARG_REG s390_r2
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.
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
#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);
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, NULL);
- }
-
- 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, NULL);
- }
-
- 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, NULL);
- }
-
- mono_trampolines_unlock ();
-#else
- code = NULL;
- g_assert_not_reached ();
-#endif
- return code;
-}
#ifdef MONO_ARCH_LLVM_SUPPORTED
/*
"delegate",
"restore_stack_prot",
"generic_virtual_remoting",
- "monitor_enter",
- "monitor_enter_v4",
- "monitor_exit",
"vcall",
"handler_block_guard"
};
#define MONO_ARCH_HAVE_GENERALIZED_IMT_THUNK 1
#define MONO_ARCH_HAVE_LIVERANGE_OPS 1
#define MONO_ARCH_HAVE_SIGCTX_TO_MONOCTX 1
-#if defined(__linux__) || defined (__APPLE__)
-#define MONO_ARCH_MONITOR_OBJECT_REG X86_EAX
-#define MONO_ARCH_MONITOR_LOCK_TAKEN_REG X86_EDX
-#endif
#if !defined(__native_client_codegen__)
#define MONO_ARCH_HAVE_FULL_AOT_TRAMPOLINES 1
#endif
#endif
/* Version number of the AOT file format */
-#define MONO_AOT_FILE_VERSION 120
+#define MONO_AOT_FILE_VERSION 121
//TODO: This is x86/amd64 specific.
#define mono_simd_shuffle_mask(a,b,c,d) ((a) | ((b) << 2) | ((c) << 4) | ((d) << 6))
MONO_TRAMPOLINE_DELEGATE,
MONO_TRAMPOLINE_RESTORE_STACK_PROT,
MONO_TRAMPOLINE_GENERIC_VIRTUAL_REMOTING,
- MONO_TRAMPOLINE_MONITOR_ENTER,
- MONO_TRAMPOLINE_MONITOR_ENTER_V4,
- MONO_TRAMPOLINE_MONITOR_EXIT,
MONO_TRAMPOLINE_VCALL,
MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD,
MONO_TRAMPOLINE_NUM
/* These trampolines return normally to their caller */
#define MONO_TRAMPOLINE_TYPE_MUST_RETURN(t) \
((t) == MONO_TRAMPOLINE_RESTORE_STACK_PROT || \
- (t) == MONO_TRAMPOLINE_RGCTX_LAZY_FETCH || \
- (t) == MONO_TRAMPOLINE_MONITOR_ENTER || \
- (t) == MONO_TRAMPOLINE_MONITOR_ENTER_V4 || \
- (t) == MONO_TRAMPOLINE_MONITOR_EXIT)
+ (t) == MONO_TRAMPOLINE_RGCTX_LAZY_FETCH)
/* These trampolines receive an argument directly in a register */
#define MONO_TRAMPOLINE_TYPE_HAS_ARG(t) \
- ((t) == MONO_TRAMPOLINE_MONITOR_ENTER || \
- (t) == MONO_TRAMPOLINE_MONITOR_ENTER_V4 || \
- (t) == MONO_TRAMPOLINE_MONITOR_EXIT || \
- (t) == MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD)
+ ((t) == MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD)
/* optimization flags */
#define OPTFLAG(id,shift,name,descr) MONO_OPT_ ## id = 1 << shift,
#include <mono/metadata/marshal.h>
#include <mono/metadata/tabledefs.h>
#include <mono/metadata/mono-debug-debugger.h>
-#include <mono/metadata/monitor.h>
#include <mono/metadata/profiler-private.h>
#include <mono/metadata/gc-internal.h>
#include <mono/arch/amd64/amd64-codegen.h>
//amd64_breakpoint (code);
#endif
- if (tramp_type != MONO_TRAMPOLINE_MONITOR_ENTER &&
- tramp_type != MONO_TRAMPOLINE_MONITOR_ENTER_V4 &&
- tramp_type != MONO_TRAMPOLINE_MONITOR_EXIT &&
- tramp_type != MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD) {
+ if (tramp_type != MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD) {
/* Obtain the trampoline argument which is encoded in the instruction stream */
if (aot) {
/* Load the GOT offset */
return buf;
}
-#ifdef MONO_ARCH_MONITOR_OBJECT_REG
-
-gpointer
-mono_arch_create_monitor_enter_trampoline (MonoTrampInfo **info, gboolean is_v4, gboolean aot)
-{
- guint8 *tramp;
- guint8 *code, *buf;
- guint8 *jump_obj_null, *jump_sync_null, *jump_cmpxchg_failed, *jump_other_owner, *jump_tid, *jump_sync_thin_hash = NULL;
- guint8 *jump_lock_taken_true = NULL;
- int tramp_size;
- int status_offset, nest_offset;
- MonoJumpInfo *ji = NULL;
- GSList *unwind_ops;
- int obj_reg = MONO_AMD64_ARG_REG1;
- int lock_taken_reg = MONO_AMD64_ARG_REG2;
- int sync_reg = MONO_AMD64_ARG_REG3;
- int tid_reg = MONO_AMD64_ARG_REG4;
- int status_reg = AMD64_RAX;
-
- 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 = 128;
-
- code = buf = mono_global_codeman_reserve (tramp_size);
-
- unwind_ops = mono_arch_get_cie_program ();
-
- if (!aot && mono_thread_get_tls_offset () != -1) {
- /* MonoObject* obj is in obj_reg */
- /* is obj null? */
- amd64_test_reg_reg (code, obj_reg, obj_reg);
- /* if yes, jump to actual trampoline */
- jump_obj_null = code;
- amd64_branch8 (code, X86_CC_Z, -1, 1);
-
- if (is_v4) {
- amd64_test_membase_imm (code, lock_taken_reg, 0, 1);
- /* if *lock_taken is 1, jump to actual trampoline */
- jump_lock_taken_true = code;
- x86_branch8 (code, X86_CC_NZ, -1, 1);
- }
-
- /* load obj->synchronization to sync_reg */
- amd64_mov_reg_membase (code, sync_reg, obj_reg, MONO_STRUCT_OFFSET (MonoObject, synchronisation), 8);
-
- if (mono_gc_is_moving ()) {
- /*if bit zero is set it's a thin hash*/
- /*FIXME use testb encoding*/
- amd64_test_reg_imm (code, sync_reg, 0x01);
- jump_sync_thin_hash = code;
- amd64_branch8 (code, X86_CC_NE, -1, 1);
-
- /*clear bits used by the gc*/
- amd64_alu_reg_imm (code, X86_AND, sync_reg, ~0x3);
- }
-
- /* is synchronization null? */
- amd64_test_reg_reg (code, sync_reg, sync_reg);
- /* if yes, jump to actual trampoline */
- jump_sync_null = code;
- amd64_branch8 (code, X86_CC_Z, -1, 1);
-
- /* load MonoInternalThread* into tid_reg */
- code = mono_amd64_emit_tls_get (code, tid_reg, mono_thread_get_tls_offset ());
- /* load TID into tid_reg */
- amd64_mov_reg_membase (code, tid_reg, tid_reg, MONO_STRUCT_OFFSET (MonoInternalThread, small_id), 4);
-
- /* is synchronization->owner free */
- amd64_mov_reg_membase (code, status_reg, sync_reg, status_offset, 4);
- amd64_test_reg_imm_size (code, status_reg, OWNER_MASK, 4);
- /* if not, jump to next case */
- jump_tid = code;
- amd64_branch8 (code, X86_CC_NZ, -1, 1);
-
- /* if yes, try a compare-exchange with the TID */
- g_assert (tid_reg != X86_EAX);
- /* Form new status in tid_reg */
- amd64_alu_reg_reg_size (code, X86_OR, tid_reg, status_reg, 4);
- /* compare and exchange */
- amd64_prefix (code, X86_LOCK_PREFIX);
- amd64_cmpxchg_membase_reg_size (code, sync_reg, status_offset, tid_reg, 4);
- /* if not successful, jump to actual trampoline */
- jump_cmpxchg_failed = code;
- amd64_branch8 (code, X86_CC_NZ, -1, 1);
- /* if successful, return */
- if (is_v4)
- amd64_mov_membase_imm (code, lock_taken_reg, 0, 1, 1);
- amd64_ret (code);
-
- /* next case: synchronization->owner is not null */
- x86_patch (jump_tid, code);
- /* is synchronization->owner == TID? */
- amd64_alu_reg_imm_size (code, X86_AND, status_reg, OWNER_MASK, 4);
- amd64_alu_reg_reg_size (code, X86_CMP, status_reg, tid_reg, 4);
- /* if not, jump to actual trampoline */
- jump_other_owner = code;
- amd64_branch8 (code, X86_CC_NZ, -1, 1);
- /* if yes, increment nest */
- amd64_inc_membase_size (code, sync_reg, nest_offset, 4);
- /* return */
- if (is_v4)
- amd64_mov_membase_imm (code, lock_taken_reg, 0, 1, 1);
- amd64_ret (code);
-
- x86_patch (jump_obj_null, code);
- if (jump_sync_thin_hash)
- x86_patch (jump_sync_thin_hash, code);
- x86_patch (jump_sync_null, code);
- x86_patch (jump_cmpxchg_failed, code);
- x86_patch (jump_other_owner, code);
- if (is_v4)
- x86_patch (jump_lock_taken_true, code);
- }
-
- /* jump to the actual trampoline */
- if (MONO_AMD64_ARG_REG1 != obj_reg)
- amd64_mov_reg_reg (code, MONO_AMD64_ARG_REG1, obj_reg, sizeof (mgreg_t));
-
- if (aot) {
- if (is_v4)
- code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, "specific_trampoline_monitor_enter_v4");
- else
- code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, "specific_trampoline_monitor_enter");
- amd64_jump_reg (code, AMD64_R11);
- } else {
- 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 */
- amd64_jump_code (code, tramp);
- }
-
- nacl_global_codeman_validate (&buf, tramp_size, &code);
-
- 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 (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;
-}
-
-gpointer
-mono_arch_create_monitor_exit_trampoline (MonoTrampInfo **info, gboolean aot)
-{
- guint8 *tramp;
- guint8 *code, *buf;
- guint8 *jump_obj_null, *jump_have_waiters, *jump_sync_null, *jump_not_owned, *jump_cmpxchg_failed;
- guint8 *jump_next, *jump_sync_thin_hash = NULL;
- int tramp_size;
- int status_offset, nest_offset;
- MonoJumpInfo *ji = NULL;
- GSList *unwind_ops;
- int obj_reg = MONO_AMD64_ARG_REG1;
- int sync_reg = MONO_AMD64_ARG_REG2;
- int status_reg = MONO_AMD64_ARG_REG3;
-
- g_assert (obj_reg == MONO_ARCH_MONITOR_OBJECT_REG);
-
- 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 = 112;
-
- code = buf = mono_global_codeman_reserve (tramp_size);
-
- unwind_ops = mono_arch_get_cie_program ();
-
- if (!aot && mono_thread_get_tls_offset () != -1) {
- /* MonoObject* obj is in obj_reg */
- /* is obj null? */
- amd64_test_reg_reg (code, obj_reg, obj_reg);
- /* if yes, jump to actual trampoline */
- jump_obj_null = code;
- amd64_branch8 (code, X86_CC_Z, -1, 1);
-
- /* load obj->synchronization to RCX */
- amd64_mov_reg_membase (code, sync_reg, obj_reg, MONO_STRUCT_OFFSET (MonoObject, synchronisation), 8);
-
- if (mono_gc_is_moving ()) {
- /*if bit zero is set it's a thin hash*/
- /*FIXME use testb encoding*/
- amd64_test_reg_imm (code, sync_reg, 0x01);
- jump_sync_thin_hash = code;
- amd64_branch8 (code, X86_CC_NE, -1, 1);
-
- /*clear bits used by the gc*/
- amd64_alu_reg_imm (code, X86_AND, sync_reg, ~0x3);
- }
-
- /* is synchronization null? */
- amd64_test_reg_reg (code, sync_reg, sync_reg);
- /* if yes, jump to actual trampoline */
- jump_sync_null = code;
- amd64_branch8 (code, X86_CC_Z, -1, 1);
-
- /* next case: synchronization is not null */
- /* load MonoInternalThread* into RAX */
- code = mono_amd64_emit_tls_get (code, AMD64_RAX, mono_thread_get_tls_offset ());
- /* load TID into RAX */
- amd64_mov_reg_membase (code, AMD64_RAX, AMD64_RAX, MONO_STRUCT_OFFSET (MonoInternalThread, small_id), 4);
- /* is synchronization->owner == TID */
- amd64_mov_reg_membase (code, status_reg, sync_reg, status_offset, 4);
- amd64_alu_reg_reg_size (code, X86_XOR, AMD64_RAX, status_reg, 4);
- amd64_test_reg_imm_size (code, AMD64_RAX, OWNER_MASK, 4);
-
- /* if no, jump to actual trampoline */
- jump_not_owned = code;
- amd64_branch8 (code, X86_CC_NZ, -1, 1);
-
- /* next case: synchronization->owner == TID */
- /* is synchronization->nest == 1 */
- amd64_alu_membase_imm_size (code, X86_CMP, sync_reg, nest_offset, 1, 4);
- /* if not, jump to next case */
- jump_next = code;
- amd64_branch8 (code, X86_CC_NZ, -1, 1);
- /* if yes, is synchronization->entry_count greater than zero */
- amd64_test_reg_imm_size (code, status_reg, ENTRY_COUNT_WAITERS, 4);
- /* if not, jump to actual trampoline */
- jump_have_waiters = code;
- amd64_branch8 (code, X86_CC_NZ, -1 , 1);
- /* if yes, try to set synchronization->owner to null and return */
- g_assert (status_reg != AMD64_RAX);
- /* old status in RAX */
- amd64_mov_reg_reg (code, AMD64_RAX, status_reg, 4);
- /* form new status */
- amd64_alu_reg_imm_size (code, X86_AND, status_reg, ENTRY_COUNT_MASK, 4);
- /* compare and exchange */
- amd64_prefix (code, X86_LOCK_PREFIX);
- amd64_cmpxchg_membase_reg_size (code, sync_reg, status_offset, status_reg, 4);
- /* if not successful, jump to actual trampoline */
- jump_cmpxchg_failed = code;
- amd64_branch8 (code, X86_CC_NZ, -1, 1);
- amd64_ret (code);
-
- /* next case: synchronization->nest is not 1 */
- x86_patch (jump_next, code);
- /* decrease synchronization->nest and return */
- amd64_dec_membase_size (code, sync_reg, nest_offset, 4);
- amd64_ret (code);
-
- if (jump_sync_thin_hash)
- x86_patch (jump_sync_thin_hash, code);
- x86_patch (jump_obj_null, code);
- x86_patch (jump_have_waiters, code);
- x86_patch (jump_not_owned, code);
- x86_patch (jump_cmpxchg_failed, code);
- x86_patch (jump_sync_null, code);
- }
-
- /* jump to the actual trampoline */
- if (MONO_AMD64_ARG_REG1 != obj_reg)
- amd64_mov_reg_reg (code, MONO_AMD64_ARG_REG1, obj_reg, sizeof (mgreg_t));
-
- if (aot) {
- code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, "specific_trampoline_monitor_exit");
- amd64_jump_reg (code, AMD64_R11);
- } else {
- tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_MONITOR_EXIT, mono_get_root_domain (), NULL);
- amd64_jump_code (code, tramp);
- }
-
- nacl_global_codeman_validate (&buf, tramp_size, &code);
-
- 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);
-
- *info = mono_tramp_info_create ("monitor_exit_trampoline", buf, code - buf, ji, unwind_ops);
-
- return buf;
-}
-
-#else
-
-gpointer
-mono_arch_create_monitor_enter_trampoline (MonoTrampInfo **info, gboolean is_v4, gboolean aot)
-{
- g_assert_not_reached ();
- return NULL;
-}
-
-gpointer
-mono_arch_create_monitor_exit_trampoline (MonoTrampInfo **info, gboolean aot)
-{
- g_assert_not_reached ();
- return NULL;
-}
-
-#endif
-
void
mono_arch_invalidate_method (MonoJitInfo *ji, void *func, gpointer func_arg)
{
#include <mono/metadata/appdomain.h>
#include <mono/metadata/gc-internal.h>
#include <mono/metadata/marshal.h>
-#include <mono/metadata/monitor.h>
#include <mono/metadata/profiler-private.h>
#include <mono/metadata/tabledefs.h>
#include <mono/arch/s390x/s390x-codegen.h>
/*----------------------------------------------------------*/
code = buf = mono_domain_code_reserve (domain, SPECIFIC_TRAMPOLINE_SIZE);
- switch (tramp_type) {
- /*
- * Monitor tramps have the object in r2
- */
- case MONO_TRAMPOLINE_MONITOR_ENTER:
- case MONO_TRAMPOLINE_MONITOR_ENTER_V4:
- case MONO_TRAMPOLINE_MONITOR_EXIT:
- s390_lgr (buf, s390_r1, s390_r2);
- break;
- default :
- S390_SET (buf, s390_r1, arg1);
- }
+ S390_SET (buf, s390_r1, arg1);
displace = (tramp - buf) / 2;
s390_jg (buf, displace);
}
/*========================= End of Function ========================*/
-
-#ifdef MONO_ARCH_MONITOR_OBJECT_REG
-/*------------------------------------------------------------------*/
-/* */
-/* Name - mono_arch_create_monitor_enter_trampoline */
-/* */
-/* Function - */
-/* */
-/*------------------------------------------------------------------*/
-
-gpointer
-mono_arch_create_monitor_enter_trampoline (MonoTrampInfo **info, gboolean is_v4, gboolean aot)
-{
- guint8 *tramp,
- *code, *buf;
- gint16 *jump_obj_null,
- *jump_sync_null,
- *jump_cs_failed,
- *jump_other_owner,
- *jump_tid,
- *jump_sync_thin_hash = NULL,
- *jump_lock_taken_true = NULL;
- int tramp_size,
- status_reg = s390_r0,
- lock_taken_reg = s390_r1,
- obj_reg = s390_r2,
- sync_reg = s390_r3,
- tid_reg = s390_r4,
- status_offset,
- nest_offset;
- MonoJumpInfo *ji = NULL;
- GSList *unwind_ops = NULL;
-
- 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;
- MonoJumpInfo *ji = NULL;
- GSList *unwind_ops = NULL;
- int obj_reg = s390_r2,
- sync_reg = s390_r3,
- status_reg = s390_r4;
-
- g_assert (obj_reg == MONO_ARCH_MONITOR_OBJECT_REG);
-
- 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);
-
- /* load obj->synchronization to RCX */
- 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);
-
- /* next case: synchronization is not null */
- /* load MonoInternalThread* into r5 */
- s390_ear (code, s390_r5, 0);
- s390_sllg(code, s390_r5, s390_r5, 0, 32);
- s390_ear (code, s390_r5, 1);
- /* load TID into r1 */
- s390_lg (code, s390_r1, 0, s390_r5, mono_thread_get_tls_offset ());
- s390_lgf (code, s390_r1, 0, s390_r1, MONO_STRUCT_OFFSET (MonoInternalThread, small_id));
- /* is synchronization->owner == TID */
- s390_lgf (code, status_reg, 0, sync_reg, status_offset);
- s390_xr (code, s390_r1, status_reg);
- s390_tmlh (code, s390_r1, OWNER_MASK);
- /* if not, jump to actual trampoline */
- s390_jno (code, 0); CODEPTR(code, jump_not_owned);
-
- /* next case: synchronization->owner == TID */
- /* is synchronization->nest == 1 */
- s390_lgf (code, s390_r0, 0, sync_reg, nest_offset);
- s390_chi (code, s390_r0, 1);
- /* if not, jump to next case */
- s390_jne (code, 0); CODEPTR(code, jump_next);
- /* if yes, is synchronization->entry_count greater than zero */
- s390_cfi (code, status_reg, ENTRY_COUNT_WAITERS);
- /* if not, jump to actual trampoline */
- s390_jnz (code, 0); CODEPTR(code, jump_have_waiters);
- /* if yes, try to set synchronization->owner to null and return */
- /* old status in s390_r0 */
- s390_lgfr (code, s390_r0, status_reg);
- /* form new status */
- s390_nilf (code, status_reg, ENTRY_COUNT_MASK);
- /* compare and exchange */
- s390_cs (code, s390_r0, status_reg, sync_reg, status_offset);
- /* if not successful, jump to actual trampoline */
- s390_jnz (code, 0); CODEPTR(code, jump_cs_failed);
- s390_br (code, s390_r14);
-
- /* next case: synchronization->nest is not 1 */
- PTRSLOT (code, jump_next);
- /* decrease synchronization->nest and return */
- s390_lgf (code, s390_r0, 0, sync_reg, nest_offset);
- s390_ahi (code, s390_r0, -1);
- s390_st (code, s390_r0, 0, sync_reg, nest_offset);
- s390_br (code, s390_r14);
-
- PTRSLOT (code, jump_obj_null);
- if (jump_sync_thin_hash)
- PTRSLOT (code, jump_sync_thin_hash);
- PTRSLOT (code, jump_have_waiters);
- PTRSLOT (code, jump_not_owned);
- PTRSLOT (code, jump_cs_failed);
- PTRSLOT (code, jump_sync_null);
- }
-
- /* jump to the actual trampoline */
- tramp = mono_arch_create_specific_trampoline (NULL, MONO_TRAMPOLINE_MONITOR_EXIT, mono_get_root_domain (), NULL);
-
- 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)
- *info = mono_tramp_info_create ("monitor_exit_trampoline", buf, code - buf, ji, unwind_ops);
-
- return buf;
-}
-
-/*========================= End of Function ========================*/
-#endif
#include <mono/metadata/tabledefs.h>
#include <mono/metadata/mono-debug.h>
#include <mono/metadata/mono-debug-debugger.h>
-#include <mono/metadata/monitor.h>
#include <mono/metadata/profiler-private.h>
#include <mono/metadata/gc-internal.h>
#include <mono/arch/x86/x86-codegen.h>
return buf;
}
-#ifdef MONO_ARCH_MONITOR_OBJECT_REG
-/*
- * The code produced by this trampoline is equivalent to this:
- *
- * if (obj) {
- * if (obj->synchronisation) {
- * if (obj->synchronisation->owner == 0) {
- * if (cmpxch (&obj->synchronisation->owner, TID, 0) == 0)
- * return;
- * }
- * if (obj->synchronisation->owner == TID) {
- * ++obj->synchronisation->nest;
- * return;
- * }
- * }
- * }
- * return full_monitor_enter ();
- *
- */
-gpointer
-mono_arch_create_monitor_enter_trampoline (MonoTrampInfo **info, gboolean is_v4, gboolean aot)
-{
- guint8 *code, *buf;
- guint8 *jump_obj_null, *jump_sync_null, *jump_other_owner, *jump_cmpxchg_failed, *jump_tid, *jump_sync_thin_hash = NULL;
- guint8 *jump_lock_taken_true = NULL;
- int tramp_size;
- int status_offset, nest_offset;
- MonoJumpInfo *ji = NULL;
- int cfa_offset;
- GSList *unwind_ops = NULL;
-
- g_assert (MONO_ARCH_MONITOR_OBJECT_REG == X86_EAX);
-#ifdef MONO_ARCH_MONITOR_LOCK_TAKEN_REG
- g_assert (MONO_ARCH_MONITOR_LOCK_TAKEN_REG == X86_EDX);
-#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 = NACL_SIZE (128, 192);
-
- code = buf = mono_global_codeman_reserve (tramp_size);
-
- cfa_offset = 4;
- unwind_ops = mono_arch_get_cie_program ();
-
- x86_push_reg (code, X86_EAX);
- cfa_offset += 4;
- mono_add_unwind_op_def_cfa_offset (unwind_ops, code, buf, cfa_offset);
- /* FIXME Unwind information */
- if (mono_thread_get_tls_offset () != -1) {
- if (is_v4) {
- x86_test_membase_imm (code, X86_EDX, 0, 1);
- /* if *lock_taken is 1, jump to actual trampoline */
- jump_lock_taken_true = code;
- x86_branch8 (code, X86_CC_NZ, -1, 1);
- x86_push_reg (code, X86_EDX);
- }
- /* MonoObject* obj is in EAX */
- /* is obj null? */
- x86_test_reg_reg (code, X86_EAX, X86_EAX);
- /* if yes, jump to actual trampoline */
- jump_obj_null = code;
- x86_branch8 (code, X86_CC_Z, -1, 1);
-
- /* load obj->synchronization to ECX */
- x86_mov_reg_membase (code, X86_ECX, X86_EAX, MONO_STRUCT_OFFSET (MonoObject, synchronisation), 4);
-
- if (mono_gc_is_moving ()) {
- /*if bit zero is set it's a thin hash*/
- /*FIXME use testb encoding*/
- x86_test_reg_imm (code, X86_ECX, 0x01);
- jump_sync_thin_hash = code;
- x86_branch8 (code, X86_CC_NE, -1, 1);
-
- /*clear bits used by the gc*/
- x86_alu_reg_imm (code, X86_AND, X86_ECX, ~0x3);
- }
-
- /* is synchronization null? */
- x86_test_reg_reg (code, X86_ECX, X86_ECX);
-
- /* if yes, jump to actual trampoline */
- jump_sync_null = code;
- x86_branch8 (code, X86_CC_Z, -1, 1);
-
- /* load MonoInternalThread* into EDX */
- if (aot) {
- /* load_aotconst () puts the result into EAX */
- x86_mov_reg_reg (code, X86_EDX, X86_EAX, sizeof (mgreg_t));
- code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_TLS_OFFSET, GINT_TO_POINTER (TLS_KEY_THREAD));
- code = mono_x86_emit_tls_get_reg (code, X86_EAX, X86_EAX);
- x86_xchg_reg_reg (code, X86_EAX, X86_EDX, sizeof (mgreg_t));
- } else {
- code = mono_x86_emit_tls_get (code, X86_EDX, mono_thread_get_tls_offset ());
- }
- /* load TID into EDX */
- x86_mov_reg_membase (code, X86_EDX, X86_EDX, MONO_STRUCT_OFFSET (MonoInternalThread, small_id), 4);
-
- /* is synchronization->owner free */
- x86_mov_reg_membase (code, X86_EAX, X86_ECX, status_offset, 4);
- x86_test_reg_imm (code, X86_EAX, OWNER_MASK);
- /* if not, jump to next case */
- jump_tid = code;
- x86_branch8 (code, X86_CC_NZ, -1, 1);
-
- /* if yes, try a compare-exchange with the TID */
- /* Form new status */
- x86_alu_reg_reg (code, X86_OR, X86_EDX, X86_EAX);
- /* compare and exchange */
- x86_prefix (code, X86_LOCK_PREFIX);
- x86_cmpxchg_membase_reg (code, X86_ECX, status_offset, X86_EDX);
- /* if not successful, jump to actual trampoline */
- jump_cmpxchg_failed = code;
- x86_branch8 (code, X86_CC_NZ, -1, 1);
- /* if successful, pop and return */
- if (is_v4) {
- x86_pop_reg (code, X86_EDX);
- x86_mov_membase_imm (code, X86_EDX, 0, 1, 1);
- }
- x86_pop_reg (code, X86_EAX);
- x86_ret (code);
-
- /* next case: synchronization->owner is not null */
- x86_patch (jump_tid, code);
- /* is synchronization->owner == TID? */
- x86_alu_reg_imm (code, X86_AND, X86_EAX, OWNER_MASK);
- x86_alu_reg_reg (code, X86_CMP, X86_EAX, X86_EDX);
- /* if not, jump to actual trampoline */
- jump_other_owner = code;
- x86_branch8 (code, X86_CC_NZ, -1, 1);
- /* if yes, increment nest */
- x86_inc_membase (code, X86_ECX, nest_offset);
- if (is_v4) {
- x86_pop_reg (code, X86_EDX);
- x86_mov_membase_imm (code, X86_EDX, 0, 1, 1);
- }
- x86_pop_reg (code, X86_EAX);
- /* return */
- x86_ret (code);
-
- /* obj is pushed, jump to the actual trampoline */
- x86_patch (jump_obj_null, code);
- if (jump_sync_thin_hash)
- x86_patch (jump_sync_thin_hash, code);
- x86_patch (jump_sync_null, code);
- x86_patch (jump_other_owner, code);
- x86_patch (jump_cmpxchg_failed, code);
-
- if (is_v4) {
- x86_pop_reg (code, X86_EDX);
- x86_patch (jump_lock_taken_true, code);
- }
- }
-
- if (aot) {
- /* We are calling the generic trampoline directly, the argument is pushed
- * on the stack just like a specific trampoline.
- */
- if (is_v4)
- code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, "generic_trampoline_monitor_enter_v4");
- else
- code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, "generic_trampoline_monitor_enter");
- x86_jump_reg (code, X86_EAX);
- } else {
- if (is_v4)
- x86_jump_code (code, mono_get_trampoline_code (MONO_TRAMPOLINE_MONITOR_ENTER_V4));
- else
- x86_jump_code (code, mono_get_trampoline_code (MONO_TRAMPOLINE_MONITOR_ENTER));
- }
-
- mono_arch_flush_icache (buf, code - buf);
- g_assert (code - buf <= tramp_size);
-
- nacl_global_codeman_validate (&buf, tramp_size, &code);
- mono_profiler_code_buffer_new (buf, code - buf, MONO_PROFILER_CODE_BUFFER_MONITOR, NULL);
-
- 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;
-}
-
-gpointer
-mono_arch_create_monitor_exit_trampoline (MonoTrampInfo **info, gboolean aot)
-{
- guint8 *tramp = mono_get_trampoline_code (MONO_TRAMPOLINE_MONITOR_EXIT);
- guint8 *code, *buf;
- guint8 *jump_obj_null, *jump_have_waiters, *jump_sync_null, *jump_not_owned, *jump_sync_thin_hash = NULL;
- guint8 *jump_next, *jump_cmpxchg_failed;
- int tramp_size;
- int status_offset, nest_offset;
- MonoJumpInfo *ji = NULL;
- GSList *unwind_ops = NULL;
-
- g_assert (MONO_ARCH_MONITOR_OBJECT_REG == X86_EAX);
-
- 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 = NACL_SIZE (128, 192);
-
- code = buf = mono_global_codeman_reserve (tramp_size);
-
- /* FIXME Unwind information */
-
- x86_push_reg (code, X86_EAX);
- if (mono_thread_get_tls_offset () != -1) {
- /* MonoObject* obj is in EAX */
- /* is obj null? */
- x86_test_reg_reg (code, X86_EAX, X86_EAX);
- /* if yes, jump to actual trampoline */
- jump_obj_null = code;
- x86_branch8 (code, X86_CC_Z, -1, 1);
-
- /* load obj->synchronization to ECX */
- x86_mov_reg_membase (code, X86_ECX, X86_EAX, MONO_STRUCT_OFFSET (MonoObject, synchronisation), 4);
-
- if (mono_gc_is_moving ()) {
- /*if bit zero is set it's a thin hash*/
- /*FIXME use testb encoding*/
- x86_test_reg_imm (code, X86_ECX, 0x01);
- jump_sync_thin_hash = code;
- x86_branch8 (code, X86_CC_NE, -1, 1);
-
- /*clear bits used by the gc*/
- x86_alu_reg_imm (code, X86_AND, X86_ECX, ~0x3);
- }
-
- /* is synchronization null? */
- x86_test_reg_reg (code, X86_ECX, X86_ECX);
- /* if yes, jump to actual trampoline */
- jump_sync_null = code;
- x86_branch8 (code, X86_CC_Z, -1, 1);
-
- /* next case: synchronization is not null */
- /* load MonoInternalThread* into EDX */
- if (aot) {
- /* load_aotconst () puts the result into EAX */
- x86_mov_reg_reg (code, X86_EDX, X86_EAX, sizeof (mgreg_t));
- code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_TLS_OFFSET, GINT_TO_POINTER (TLS_KEY_THREAD));
- code = mono_x86_emit_tls_get_reg (code, X86_EAX, X86_EAX);
- x86_xchg_reg_reg (code, X86_EAX, X86_EDX, sizeof (mgreg_t));
- } else {
- code = mono_x86_emit_tls_get (code, X86_EDX, mono_thread_get_tls_offset ());
- }
- /* load TID into EDX */
- x86_mov_reg_membase (code, X86_EDX, X86_EDX, MONO_STRUCT_OFFSET (MonoInternalThread, small_id), 4);
- /* is synchronization->owner == TID */
- x86_mov_reg_membase (code, X86_EAX, X86_ECX, status_offset, 4);
- x86_alu_reg_reg (code, X86_XOR, X86_EDX, X86_EAX);
- x86_test_reg_imm (code, X86_EDX, OWNER_MASK);
- /* if no, jump to actual trampoline */
- jump_not_owned = code;
- x86_branch8 (code, X86_CC_NZ, -1, 1);
-
- /* next case: synchronization->owner == TID */
- /* is synchronization->nest == 1 */
- x86_alu_membase_imm (code, X86_CMP, X86_ECX, nest_offset, 1);
- /* if not, jump to next case */
- jump_next = code;
- x86_branch8 (code, X86_CC_NZ, -1, 1);
- /* if yes, is synchronization->entry_count greater than zero? */
- x86_test_reg_imm (code, X86_EAX, ENTRY_COUNT_WAITERS);
- /* if yes, jump to actual trampoline */
- jump_have_waiters = code;
- x86_branch8 (code, X86_CC_NZ, -1 , 1);
- /* if not, try to set synchronization->owner to null and return */
- x86_mov_reg_reg (code, X86_EDX, X86_EAX, 4);
- x86_alu_reg_imm (code, X86_AND, X86_EDX, ENTRY_COUNT_MASK);
- /* compare and exchange */
- x86_prefix (code, X86_LOCK_PREFIX);
- /* EAX contains the previous status */
- x86_cmpxchg_membase_reg (code, X86_ECX, status_offset, X86_EDX);
- /* if not successful, jump to actual trampoline */
- jump_cmpxchg_failed = code;
- x86_branch8 (code, X86_CC_NZ, -1, 1);
-
- x86_pop_reg (code, X86_EAX);
- x86_ret (code);
-
- /* next case: synchronization->nest is not 1 */
- x86_patch (jump_next, code);
- /* decrease synchronization->nest and return */
- x86_dec_membase (code, X86_ECX, nest_offset);
- x86_pop_reg (code, X86_EAX);
- x86_ret (code);
-
- /* push obj and jump to the actual trampoline */
- x86_patch (jump_obj_null, code);
- if (jump_sync_thin_hash)
- x86_patch (jump_sync_thin_hash, code);
- x86_patch (jump_have_waiters, code);
- x86_patch (jump_cmpxchg_failed, code);
- x86_patch (jump_not_owned, code);
- x86_patch (jump_sync_null, code);
- }
-
- /* obj is pushed, jump to the actual trampoline */
- if (aot) {
- code = mono_arch_emit_load_aotconst (buf, code, &ji, MONO_PATCH_INFO_JIT_ICALL_ADDR, "generic_trampoline_monitor_exit");
- x86_jump_reg (code, X86_EAX);
- } else {
- x86_jump_code (code, tramp);
- }
-
- nacl_global_codeman_validate (&buf, tramp_size, &code);
-
- mono_arch_flush_icache (buf, code - buf);
- g_assert (code - buf <= tramp_size);
- mono_profiler_code_buffer_new (buf, code - buf, MONO_PROFILER_CODE_BUFFER_MONITOR, NULL);
-
- *info = mono_tramp_info_create ("monitor_exit_trampoline", buf, code - buf, ji, unwind_ops);
-
- return buf;
-}
-
-#else
-
-gpointer
-mono_arch_create_monitor_enter_trampoline (MonoTrampInfo **info, gboolean is_v4, gboolean aot)
-{
- g_assert_not_reached ();
- return NULL;
-}
-
-gpointer
-mono_arch_create_monitor_exit_trampoline (MonoTrampInfo **info, gboolean aot)
-{
- g_assert_not_reached ();
- return NULL;
-}
-
-#endif
-
void
mono_arch_invalidate_method (MonoJitInfo *ji, void *func, gpointer func_arg)
{