Merge remote branch 'upstream/master'
[mono.git] / mono / mini / mini.h
index 5d9c7658998c6b32fbdace3cfe338e28e1ac7f3e..33764f2bf5dec4379556c7337763c49ebf8433b6 100644 (file)
@@ -72,6 +72,25 @@ typedef gint64 mgreg_t;
 #define COMPILE_SOFT_FLOAT(cfg) 0
 #endif
 
+#ifdef ENABLE_LLVM
+#define LLVM_CHECK_VERSION(major,minor) \
+       ((LLVM_MAJOR_VERSION > (major)) ||                                                                      \
+        ((LLVM_MAJOR_VERSION == (major)) && (LLVM_MINOR_VERSION >= (minor))))
+#else
+#define LLVM_CHECK_VERSION(major,minor) 0
+#endif
+
+/* 
+ * Whenever we are using mono's LLVM branch.
+ * This can be used in if statements, code which references new definitions from the branch
+ * still needs an #ifdef LLVM_MONO_BRANCH.
+ */
+#ifdef LLVM_MONO_BRANCH
+#define IS_LLVM_MONO_BRANCH 1
+#else
+#define IS_LLVM_MONO_BRANCH 0
+#endif
+
 #define NOT_IMPLEMENTED do { g_assert_not_reached (); } while (0)
 
 /* for 32 bit systems */
@@ -87,15 +106,12 @@ typedef gint64 mgreg_t;
 #define inst_ls_word data.op[MINI_LS_WORD_IDX].const_val
 #define inst_ms_word data.op[MINI_MS_WORD_IDX].const_val
 
-#define MONO_FAKE_IMT_METHOD ((MonoMethod*)GINT_TO_POINTER(-1))
-#define MONO_FAKE_VTABLE_METHOD ((MonoMethod*)GINT_TO_POINTER(-2))
-
 #ifndef DISABLE_AOT
 #define MONO_USE_AOT_COMPILER
 #endif
 
 /* Version number of the AOT file format */
-#define MONO_AOT_FILE_VERSION "68"
+#define MONO_AOT_FILE_VERSION 72
 
 //TODO: This is x86/amd64 specific.
 #define mono_simd_shuffle_mask(a,b,c,d) ((a) | ((b) << 2) | ((c) << 4) | ((d) << 6))
@@ -126,22 +142,80 @@ typedef enum {
 
 typedef enum {
        MONO_AOT_FILE_FLAG_WITH_LLVM = 1,
-       MONO_AOT_FILE_FLAG_FULL_AOT = 2
+       MONO_AOT_FILE_FLAG_FULL_AOT = 2,
+       MONO_AOT_FILE_FLAG_DEBUG = 4
 } MonoAotFileFlags;
 
 /* This structure is stored in the AOT file */
 typedef struct MonoAotFileInfo
 {
+       /* The version number of the AOT file format, should match MONO_AOT_FILE_VERSION */
+       guint32 version;
+       /* For alignment */
+       guint32 dummy;
+
+       /* All the pointers should be at the start to avoid alignment problems */
+
+       /* Mono's Global Offset Table */
+       gpointer got;
+       /* Compiled code for methods */
+       gpointer methods;
+       /* Mono EH Frame created by llc when using LLVM */
+       gpointer mono_eh_frame;
+       /* Data blob */
+       gpointer blob;
+       gpointer class_name_table;
+       gpointer class_info_offsets;
+       gpointer method_info_offsets;
+       gpointer ex_info_offsets;
+       gpointer code_offsets;
+       gpointer extra_method_info_offsets;
+       gpointer extra_method_table;
+       gpointer got_info_offsets;
+       gpointer methods_end;
+       gpointer unwind_info;
+       gpointer mem_end;
+       gpointer image_table;
+       /* Start of Mono's Program Linkage Table */
+       gpointer plt;
+       /* End of Mono's Program Linkage Table */
+       gpointer plt_end;
+       /* The GUID of the assembly which the AOT image was generated from */
+       gpointer assembly_guid;
+       /*
+        * The runtime version string for AOT images generated using 'bind-to-runtime-version',
+        * NULL otherwise.
+        */
+       gpointer runtime_version;
+       /* Blocks of various kinds of trampolines */
+       gpointer specific_trampolines;
+       gpointer static_rgctx_trampolines;
+       gpointer imt_thunks;
+       /*
+        * The end of LLVM generated thumb code, or NULL.
+        */
+       gpointer thumb_end;
+
+       /* The index of the first GOT slot used by the PLT */
        guint32 plt_got_offset_base;
+       /* Number of entries in the GOT */
        guint32 got_size;
+       /* Number of entries in the PLT */
        guint32 plt_size;
+       /* Number of methods */
        guint32 nmethods;
+       /* A union of MonoAotFileFlags */
        guint32 flags;
        /* Optimization flags used to compile the module */
        guint32 opts;
+       /* Index of the blob entry holding the GC used by this module */
+       gint32 gc_name_index;
 
+       /* Number of trampolines */
        guint32 num_trampolines [MONO_AOT_TRAMP_NUM];
+       /* The indexes of the first GOT slots used by the trampolines */
        guint32 trampoline_got_offset_base [MONO_AOT_TRAMP_NUM];
+       /* The size of one trampoline */
        guint32 trampoline_size [MONO_AOT_TRAMP_NUM];
 } MonoAotFileInfo;
 
@@ -202,22 +276,25 @@ typedef enum {
 typedef struct {
        StackFrameType type;
        /* 
-        * For FRAME_TYPE_MANAGED.
-        * For FRAME_TYPE_MANAGED_TO_NATIVE, the ji for the method which transitioned to
-        * native code, if there is one, else NULL.
+        * For FRAME_TYPE_MANAGED, otherwise NULL.
         */
        MonoJitInfo *ji;
        /*
-        * For FRAME_TYPE_MANAGED_TO_NATIVE, it is either the method which transitioned 
-        * to native code, or the method which was JITted.
+        * Same as ji->method.
         */
        MonoMethod *method;
+       /*
+        * If ji->method is a gshared method, this is the actual method instance.
+        */
+       MonoMethod *actual_method;
        /* The domain containing the code executed by this frame */
        MonoDomain *domain;
        gboolean managed;
        int native_offset;
        int il_offset;
        gpointer lmf;
+       guint32 unwind_info_len;
+       guint8 *unwind_info;
 } StackFrameInfo;
 
 typedef struct {
@@ -346,7 +423,7 @@ enum {
 #define MONO_JUMP_TABLE_FROM_INS(ins) (((ins)->opcode == OP_JUMP_TABLE) ? (ins)->inst_p0 : (((ins)->opcode == OP_AOTCONST) && (ins->inst_i1 == (gpointer)MONO_PATCH_INFO_SWITCH) ? (ins)->inst_p0 : (((ins)->opcode == OP_SWITCH) ? (ins)->inst_p0 : ((((ins)->opcode == OP_GOT_ENTRY) && ((ins)->inst_right->inst_i1 == (gpointer)MONO_PATCH_INFO_SWITCH)) ? (ins)->inst_right->inst_p0 : NULL))))
 
 /* FIXME: Add more instructions */
-#define MONO_INS_HAS_NO_SIDE_EFFECT(ins) (MONO_IS_MOVE (ins) || (ins->opcode == OP_ICONST) || (ins->opcode == OP_I8CONST) || MONO_IS_ZERO (ins) || (ins->opcode == OP_ADD_IMM) || (ins->opcode == OP_R8CONST) || (ins->opcode == OP_LADD_IMM) || (ins->opcode == OP_ISUB_IMM) || (ins->opcode == OP_IADD_IMM) || (ins->opcode == OP_INEG) || (ins->opcode == OP_LNEG) || (ins->opcode == OP_ISUB) || (ins->opcode == OP_CMOV_IGE) || (ins->opcode == OP_ISHL_IMM) || (ins->opcode == OP_ISHR_IMM) || (ins->opcode == OP_ISHR_UN_IMM) || (ins->opcode == OP_IAND_IMM) || (ins->opcode == OP_ICONV_TO_U1) || (ins->opcode == OP_ICONV_TO_I1) || (ins->opcode == OP_SEXT_I4) || (ins->opcode == OP_LCONV_TO_U1) || (ins->opcode == OP_ICONV_TO_U2) || (ins->opcode == OP_ICONV_TO_I2) || (ins->opcode == OP_LCONV_TO_I2))
+#define MONO_INS_HAS_NO_SIDE_EFFECT(ins) (MONO_IS_MOVE (ins) || (ins->opcode == OP_ICONST) || (ins->opcode == OP_I8CONST) || MONO_IS_ZERO (ins) || (ins->opcode == OP_ADD_IMM) || (ins->opcode == OP_R8CONST) || (ins->opcode == OP_LADD_IMM) || (ins->opcode == OP_ISUB_IMM) || (ins->opcode == OP_IADD_IMM) || (ins->opcode == OP_INEG) || (ins->opcode == OP_LNEG) || (ins->opcode == OP_ISUB) || (ins->opcode == OP_CMOV_IGE) || (ins->opcode == OP_ISHL_IMM) || (ins->opcode == OP_ISHR_IMM) || (ins->opcode == OP_ISHR_UN_IMM) || (ins->opcode == OP_IAND_IMM) || (ins->opcode == OP_ICONV_TO_U1) || (ins->opcode == OP_ICONV_TO_I1) || (ins->opcode == OP_SEXT_I4) || (ins->opcode == OP_LCONV_TO_U1) || (ins->opcode == OP_ICONV_TO_U2) || (ins->opcode == OP_ICONV_TO_I2) || (ins->opcode == OP_LCONV_TO_I2) || (ins->opcode == OP_LDADDR))
 
 #define MONO_METHOD_IS_FINAL(m) (((m)->flags & METHOD_ATTRIBUTE_FINAL) || ((m)->klass && ((m)->klass->flags & TYPE_ATTRIBUTE_SEALED)))
 
@@ -424,6 +501,26 @@ struct MonoSpillInfo {
        int offset;
 };
 
+/*
+ * Information about a call site for the GC map creation code
+ */
+typedef struct {
+       /* The next offset after the call instruction */
+       int pc_offset;
+       /* The basic block containing the call site */
+       MonoBasicBlock *bb;
+       /* 
+        * The set of variables live at the call site.
+        * Has length cfg->num_varinfo in bits.
+        */
+       guint8 *liveness;
+       /*
+        * List of OP_GC_PARAM_SLOT_LIVENESS_DEF instructions defining the param slots
+        * used by this call.
+        */
+       GSList *param_slots;
+} GCCallSite;
+
 /*
  * The IR-level extended basic block.  
  *
@@ -467,7 +564,10 @@ struct MonoBasicBlock {
 
        /* The offset of the generated code, used for fixups */
        int native_offset;
+       /* The length of the generated code, doesn't include alignment padding */
        int native_length;
+       /* The real native offset, which includes alignment padding too */
+       int real_native_offset;
        int max_offset;
        int max_length;
 
@@ -505,6 +605,14 @@ struct MonoBasicBlock {
        guint has_jump_table : 1;
        /* Whenever this bblock contains an OP_CALL_HANDLER instruction */
        guint has_call_handler : 1;
+       /* Whenever this bblock starts a try block */
+       guint try_start : 1;
+       /*
+        * If this is set, extend the try range started by this bblock by an arch specific
+        * number of bytes to encompass the end of the previous bblock (e.g. a Monitor.Enter
+        * call).
+        */
+       guint extend_try_block : 1;
        
        /* use for liveness analysis */
        MonoBitSet *gen_set;
@@ -523,6 +631,11 @@ struct MonoBasicBlock {
        GSList *seq_points;
        MonoInst *last_seq_point;
 
+       GSList *spill_slot_defs;
+
+       /* List of call sites in this bblock sorted by pc_offset */
+       GSList *gc_callsites;
+
        /*
         * The region encodes whether the basic block is inside
         * a finally, catch, filter or none of these.
@@ -536,7 +649,7 @@ struct MonoBasicBlock {
         *        | clause-flags |   MONO_REGION  | clause-index 
         *
         */
-        guint region;
+       guint region;
 
        /* The current symbolic register number, used in local register allocation. */
        guint32 max_vreg;
@@ -544,11 +657,13 @@ struct MonoBasicBlock {
 
 /* BBlock flags */
 enum {
-       BB_VISITED            = 1 << 0,
-       BB_REACHABLE          = 1 << 1,
-       BB_EXCEPTION_DEAD_OBJ = 1 << 2,
-       BB_EXCEPTION_UNSAFE   = 1 << 3,
-       BB_EXCEPTION_HANDLER  = 1 << 4
+       BB_VISITED              = 1 << 0,
+       BB_REACHABLE            = 1 << 1,
+       BB_EXCEPTION_DEAD_OBJ   = 1 << 2,
+       BB_EXCEPTION_UNSAFE     = 1 << 3,
+       BB_EXCEPTION_HANDLER    = 1 << 4,
+       /* for Native Client, mark the blocks that can be jumped to indirectly */
+       BB_INDIRECT_JUMP_TARGET = 1 << 5 
 };
 
 typedef struct MonoMemcpyArgs {
@@ -573,6 +688,16 @@ typedef struct {
 
 typedef struct {
        LLVMArgInfo ret;
+       /* Whenever there is an rgctx argument */
+       gboolean rgctx_arg;
+       /* Whenever there is an IMT argument */
+       gboolean imt_arg;
+       /* 
+        * The position of the vret arg in the argument list.
+        * Only if ret->storage == ArgVtypeRetAddr.
+        * Should be 0 or 1.
+        */
+       int vret_arg_index;
        /* args [0] is for the this argument if it exists */
        LLVMArgInfo args [1];
 } LLVMCallInfo;
@@ -630,6 +755,7 @@ struct MonoInst {
                gboolean record_cast_details; /* For CEE_CASTCLASS */
                MonoInst *spill_var; /* for OP_ICONV_TO_R8_RAW and OP_FCONV_TO_R8_X */
                guint16 source_opcode; /*OP_XCONV_R8_TO_I4 needs to know which op was used to do proper widening*/
+               int pc_offset; /* OP_GC_LIVERANGE_START/END */
        } backend;
        
        MonoClass *klass;
@@ -663,6 +789,7 @@ struct MonoCallInst {
        GSList *out_freg_args;
 #ifdef ENABLE_LLVM
        LLVMCallInfo *cinfo;
+       int rgctx_arg_reg, imt_arg_reg;
 #endif
 };
 
@@ -694,7 +821,16 @@ enum {
        MONO_INST_INDIRECT   = 16,
        MONO_INST_NORANGECHECK   = 16,
        /* On loads, the source address can be null */
-       MONO_INST_FAULT = 32
+       MONO_INST_FAULT = 32,
+       /* On loads, the source address points to a constant value */
+       MONO_INST_CONSTANT_LOAD = 64,
+       /* On variables, the variable needs GC tracking */
+       MONO_INST_GC_TRACK = 128,
+       /*
+        * Set on instructions during code emission which make calls, i.e. OP_CALL, OP_THROW.
+        * backend.pc_offset will be set to the pc offset at the end of the native call instructions.
+        */
+       MONO_INST_GC_CALLSITE = 128
 };
 
 #define inst_c0 data.op[0].const_val
@@ -799,6 +935,19 @@ struct MonoMethodVar {
        gint32         vreg;
 };
 
+/*
+ * Stores state need to resume exception handling when using LLVM
+ */
+typedef struct {
+       MonoJitInfo *ji;
+       int clause_index;
+       MonoContext ctx, new_ctx;
+       /* FIXME: GC */
+       gpointer        ex_obj;
+       MonoLMF *lmf;
+       int first_filter_idx, filter_idx;
+} ResumeState;
+
 typedef struct {
        gpointer          end_of_stack;
        guint32           stack_size;
@@ -817,16 +966,37 @@ typedef struct {
        /* Used to implement --debug=casts */
        MonoClass       *class_cast_from, *class_cast_to;
 
-       /* Stores state needed by mono_resume_unwind () and the handler block with a guard */
+       /* Stores state needed by handler block with a guard */
        MonoContext     ex_ctx;
-       /* FIXME: GC */
-       gpointer        ex_obj;
-       /* handle block return address */
+       ResumeState resume_state;
+
+       /*Variabled use to implement handler blocks (finally/catch/etc) guards during interruption*/
+       /* handler block return address */
        gpointer handler_block_return_address;
-       /* handler block been guarded */
+
+       /* handler block been guarded. It's safe to store this even for dynamic methods since there
+       is an activation on stack making sure it will remain alive.*/
        MonoJitExceptionInfo *handler_block;
+
+       /* context to be used by the guard trampoline when resuming interruption.*/
+       MonoContext handler_block_context;
+       /* 
+        * Stores the state at the exception throw site to be used by mono_stack_walk ()
+        * when it is called from profiler functions during exception handling.
+        */
+       MonoContext orig_ex_ctx;
+       gboolean orig_ex_ctx_set;
 } MonoJitTlsData;
 
+/*
+ * This structure is an extension of MonoLMF and contains extra information.
+ */
+typedef struct {
+       struct MonoLMF lmf;
+       gboolean debugger_invoke;
+       MonoContext ctx; /* if debugger_invoke is TRUE */
+} MonoLMFExt;
+
 typedef enum {
 #define PATCH_INFO(a,b) MONO_PATCH_INFO_ ## a,
 #include "patch-info.h"
@@ -912,9 +1082,7 @@ typedef enum {
        MONO_TRAMPOLINE_GENERIC_VIRTUAL_REMOTING,
        MONO_TRAMPOLINE_MONITOR_ENTER,
        MONO_TRAMPOLINE_MONITOR_EXIT,
-#ifdef MONO_ARCH_LLVM_SUPPORTED
-       MONO_TRAMPOLINE_LLVM_VCALL,
-#endif
+       MONO_TRAMPOLINE_VCALL,
 #ifdef MONO_ARCH_HAVE_HANDLER_BLOCK_GUARD
        MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD,
 #endif
@@ -945,10 +1113,20 @@ enum {
 
 #define MONO_BBLOCK_IS_IN_REGION(bblock, regtype) (((bblock)->region & (0xf << 4)) == (regtype))
 
+#define MONO_REGION_FLAGS(region) ((region) & 0x7)
+
 #define get_vreg_to_inst(cfg, vreg) ((vreg) < (cfg)->vreg_to_inst_len ? (cfg)->vreg_to_inst [(vreg)] : NULL)
 
 #define vreg_is_volatile(cfg, vreg) (G_UNLIKELY (get_vreg_to_inst ((cfg), (vreg)) && (get_vreg_to_inst ((cfg), (vreg))->flags & (MONO_INST_VOLATILE|MONO_INST_INDIRECT))))
 
+#ifdef HAVE_SGEN_GC
+#define vreg_is_ref(cfg, vreg) ((vreg) < (cfg)->vreg_is_ref_len ? (cfg)->vreg_is_ref [(vreg)] : 0)
+#define vreg_is_mp(cfg, vreg) ((vreg) < (cfg)->vreg_is_mp_len ? (cfg)->vreg_is_mp [(vreg)] : 0)
+#else
+#define vreg_is_ref(cfg, vreg) FALSE
+#define vreg_is_mp(cfg, vreg) FALSE
+#endif
+
 /*
  * Control Flow Graph and compilation unit information
  */
@@ -977,7 +1155,6 @@ typedef struct {
        gint             stack_offset;
        gint             max_ireg;
        gint             cil_offset_to_bb_len;
-       gint             locals_min_stack_offset, locals_max_stack_offset;
        MonoRegState    *rs;
        MonoSpillInfo   *spill_info [16]; /* machine register spills */
        gint             spill_count;
@@ -1029,6 +1206,11 @@ typedef struct {
        MonoGenericSharingContext *generic_sharing_context;
 
        unsigned char   *cil_start;
+#ifdef __native_client_codegen__
+       /* this alloc is not aligned, native_code */
+       /* is the 32-byte aligned version of this */
+       unsigned char   *native_code_alloc;
+#endif
        unsigned char   *native_code;
        guint            code_size;
        guint            code_len;
@@ -1061,12 +1243,14 @@ typedef struct {
        guint            disable_reuse_registers : 1;
        guint            disable_reuse_stack_slots : 1;
        guint            disable_reuse_ref_stack_slots : 1;
+       guint            disable_ref_noref_stack_slot_share : 1;
        guint            disable_initlocals_opt : 1;
        guint            disable_initlocals_opt_refs : 1;
        guint            disable_omit_fp : 1;
        guint            disable_vreg_to_lvreg : 1;
        guint            disable_deadce_vars : 1;
        guint            disable_out_of_line_bblocks : 1;
+       guint            gen_write_barriers : 1;
        guint            init_ref_vars : 1;
        guint            extend_live_ranges : 1;
        guint            compute_precise_live_ranges : 1;
@@ -1077,6 +1261,7 @@ typedef struct {
        guint            keep_cil_nops : 1;
        guint            gen_seq_points : 1;
        guint            explicit_null_checks : 1;
+       guint            compute_gc_maps : 1;
        gpointer         debug_info;
        guint32          lmf_offset;
     guint16          *intvars;
@@ -1104,6 +1289,20 @@ typedef struct {
        /* Size of above array */
        guint32 vreg_to_inst_len;
 
+       /* Marks vregs which hold a GC ref */
+       /* FIXME: Use a bitmap */
+       gboolean *vreg_is_ref;
+
+       /* Size of above array */
+       guint32 vreg_is_ref_len;
+
+       /* Marks vregs which hold a managed pointer */
+       /* FIXME: Use a bitmap */
+       gboolean *vreg_is_mp;
+
+       /* Size of above array */
+       guint32 vreg_is_mp_len;
+
        /* 
         * The original method to compile, differs from 'method' when doing generic
         * sharing.
@@ -1145,15 +1344,38 @@ typedef struct {
        /* The encoded sequence point info */
        MonoSeqPointInfo *seq_point_info;
 
+       /* Method headers which need to be freed after compilation */
+       GSList *headers_to_free;
+
        /* Used by AOT */
        guint32 got_offset, ex_info_offset, method_info_offset;
        /* Symbol used to refer to this method in generated assembly */
        char *asm_symbol;
+       char *llvm_method_name;
 
        MonoJitExceptionInfo *llvm_ex_info;
        guint32 llvm_ex_info_len;
+       int llvm_this_reg, llvm_this_offset;
 
        GSList *try_block_holes;
+
+       /* GC Maps */
+   
+       /* The offsets of the locals area relative to the frame pointer */
+       gint locals_min_stack_offset, locals_max_stack_offset;
+
+       /* The final CFA rule at the end of the prolog */
+       int cfa_reg, cfa_offset;
+
+       /* Points to a MonoCompileGC */
+       gpointer gc_info;
+
+       /*
+        * The encoded GC map along with its size. This contains binary data so it can be saved in an AOT
+        * image etc, but it requires a 4 byte alignment.
+        */
+       guint8 *gc_map;
+       guint32 gc_map_size;
 } MonoCompile;
 
 typedef enum {
@@ -1172,7 +1394,6 @@ typedef struct {
        gulong methods_compiled;
        gulong methods_aot;
        gulong methods_lookups;
-       gulong method_trampolines;
        gulong allocate_var;
        gulong cil_code_size;
        gulong native_code_size;
@@ -1193,8 +1414,11 @@ typedef struct {
        gulong cas_linkdemand;
        gulong cas_demand_generation;
        gulong generic_virtual_invocations;
+    int methods_with_llvm;
+       int methods_without_llvm;
        char *max_ratio_method;
        char *biggest_method;
+       double jit_time;
        gboolean enabled;
 } MonoJitStats;
 
@@ -1221,6 +1445,7 @@ enum {
 #define OP_PCONST OP_I8CONST
 #define OP_PADD OP_LADD
 #define OP_PADD_IMM OP_LADD_IMM
+#define OP_PAND_IMM OP_LAND_IMM
 #define OP_PSUB OP_LSUB
 #define OP_PMUL OP_LMUL
 #define OP_PMUL_IMM OP_LMUL_IMM
@@ -1243,6 +1468,7 @@ enum {
 #define OP_PCONST OP_ICONST
 #define OP_PADD OP_IADD
 #define OP_PADD_IMM OP_IADD_IMM
+#define OP_PAND_IMM OP_IAND_IMM
 #define OP_PSUB OP_ISUB
 #define OP_PMUL OP_IMUL
 #define OP_PMUL_IMM OP_IMUL_IMM
@@ -1264,7 +1490,7 @@ enum {
 #endif
 
 /* Opcodes to load/store regsize quantities */
-#ifdef __mono_ilp32__
+#if defined (__mono_ilp32__)
 #define OP_LOADR_MEMBASE OP_LOADI8_MEMBASE
 #define OP_STORER_MEMBASE_REG OP_STOREI8_MEMBASE_REG
 #else
@@ -1336,6 +1562,7 @@ typedef struct {
 typedef struct {
        gboolean handle_sigint;
        gboolean keep_delegates;
+       gboolean reverse_pinvoke_exceptions;
        gboolean collect_pagefault_stats;
        gboolean break_on_unverified;
        gboolean better_cast_details;
@@ -1387,6 +1614,7 @@ enum {
        MONO_EXC_INVALID_CAST,
        MONO_EXC_NULL_REF,
        MONO_EXC_ARRAY_TYPE_MISMATCH,
+       MONO_EXC_ARGUMENT,
        MONO_EXC_INTRINS_NUM
 };
 
@@ -1396,16 +1624,30 @@ enum {
        MINI_TOKEN_SOURCE_FIELD
 };
 
-/* 
- * This structures contains information about a trampoline function required by
- * the AOT compiler in full-aot mode.
- */
-typedef struct
-{
-       guint8 *code;
-       guint32 code_size;
-       char *name;
-} MonoAotTrampInfo;
+ /* 
+  * Information about a trampoline function.
+  */
+ typedef struct
+ {
+       /* 
+        * The native code of the trampoline. Not owned by this structure.
+        */
+       guint8 *code;
+       guint32 code_size;
+       /*
+        * The name of the trampoline which can be used in AOT/xdebug. Owned by this
+        * structure.
+        */
+       char *name;
+       /* 
+        * Patches required by the trampoline when aot-ing. Owned by this structure.
+        */
+       MonoJumpInfo *ji;
+       /*
+        * Unwind information. Owned by this structure.
+        */
+       GSList *unwind_ops;
+} MonoTrampInfo;
 
 typedef void (*MonoInstFunc) (MonoInst *tree, gpointer data);
 
@@ -1423,11 +1665,11 @@ MonoJumpInfoToken* mono_jump_info_token_new (MonoMemPool *mp, MonoImage *image,
 MonoJumpInfoToken* mono_jump_info_token_new2 (MonoMemPool *mp, MonoImage *image, guint32 token, MonoGenericContext *context) MONO_INTERNAL;
 MonoInst* mono_find_spvar_for_region        (MonoCompile *cfg, int region) MONO_INTERNAL;
 MonoInst* mono_find_exvar_for_offset        (MonoCompile *cfg, int offset) MONO_INTERNAL;
-int       mono_get_block_region_notry       (MonoCompile *cfg, int region) MONO_INTERNAL;
+int       mono_get_block_region_notry       (MonoCompile *cfg, int region) MONO_LLVM_INTERNAL;
 
 void      mono_precompile_assemblies        (void) MONO_INTERNAL;
 int       mono_parse_default_optimizations  (const char* p);
-void      mono_bblock_add_inst              (MonoBasicBlock *bb, MonoInst *inst) MONO_INTERNAL;
+void      mono_bblock_add_inst              (MonoBasicBlock *bb, MonoInst *inst) MONO_LLVM_INTERNAL;
 void      mono_bblock_insert_after_ins      (MonoBasicBlock *bb, MonoInst *ins, MonoInst *ins_to_insert) MONO_INTERNAL;
 void      mono_bblock_insert_before_ins     (MonoBasicBlock *bb, MonoInst *ins, MonoInst *ins_to_insert) MONO_INTERNAL;
 void      mono_verify_bblock                (MonoBasicBlock *bb) MONO_INTERNAL;
@@ -1435,7 +1677,7 @@ void      mono_verify_cfg                   (MonoCompile *cfg) MONO_INTERNAL;
 void      mono_constant_fold                (MonoCompile *cfg) MONO_INTERNAL;
 MonoInst* mono_constant_fold_ins            (MonoCompile *cfg, MonoInst *ins, MonoInst *arg1, MonoInst *arg2, gboolean overwrite) MONO_INTERNAL;
 int       mono_eval_cond_branch             (MonoInst *branch) MONO_INTERNAL;
-int       mono_is_power_of_two              (guint32 val) MONO_INTERNAL;
+int       mono_is_power_of_two              (guint32 val) MONO_LLVM_INTERNAL;
 void      mono_cprop_local                  (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst **acp, int acp_size) MONO_INTERNAL;
 MonoInst* mono_compile_create_var           (MonoCompile *cfg, MonoType *type, int opcode) MONO_INTERNAL;
 MonoInst* mono_compile_create_var_for_vreg  (MonoCompile *cfg, MonoType *type, int opcode, int vreg) MONO_INTERNAL;
@@ -1443,10 +1685,15 @@ void      mono_compile_make_var_load        (MonoCompile *cfg, MonoInst *dest, g
 MonoInst* mono_compile_create_var_load      (MonoCompile *cfg, gssize var_index) MONO_INTERNAL;
 MonoInst* mono_compile_create_var_store     (MonoCompile *cfg, gssize var_index, MonoInst *value) MONO_INTERNAL;
 MonoType* mono_type_from_stack_type         (MonoInst *ins) MONO_INTERNAL;
-guint32   mono_alloc_ireg                   (MonoCompile *cfg) MONO_INTERNAL;
-guint32   mono_alloc_freg                   (MonoCompile *cfg) MONO_INTERNAL;
-guint32   mono_alloc_preg                   (MonoCompile *cfg) MONO_INTERNAL;
+guint32   mono_alloc_ireg                   (MonoCompile *cfg) MONO_LLVM_INTERNAL;
+guint32   mono_alloc_freg                   (MonoCompile *cfg) MONO_LLVM_INTERNAL;
+guint32   mono_alloc_preg                   (MonoCompile *cfg) MONO_LLVM_INTERNAL;
 guint32   mono_alloc_dreg                   (MonoCompile *cfg, MonoStackType stack_type) MONO_INTERNAL;
+guint32   mono_alloc_ireg_ref               (MonoCompile *cfg) MONO_LLVM_INTERNAL;
+guint32   mono_alloc_ireg_mp                (MonoCompile *cfg) MONO_LLVM_INTERNAL;
+guint32   mono_alloc_ireg_copy              (MonoCompile *cfg, guint32 vreg) MONO_LLVM_INTERNAL;
+void      mono_mark_vreg_as_ref             (MonoCompile *cfg, int vreg) MONO_INTERNAL;
+void      mono_mark_vreg_as_mp              (MonoCompile *cfg, int vreg) MONO_INTERNAL;
 
 void      mono_link_bblock                  (MonoCompile *cfg, MonoBasicBlock *from, MonoBasicBlock* to) MONO_INTERNAL;
 void      mono_unlink_bblock                (MonoCompile *cfg, MonoBasicBlock *from, MonoBasicBlock* to) MONO_INTERNAL;
@@ -1479,7 +1726,7 @@ MonoJumpInfo* mono_patch_info_dup_mp        (MonoMemPool *mp, MonoJumpInfo *patc
 guint     mono_patch_info_hash (gconstpointer data) MONO_INTERNAL;
 gint      mono_patch_info_equal (gconstpointer ka, gconstpointer kb) MONO_INTERNAL;
 MonoJumpInfo *mono_patch_info_list_prepend  (MonoJumpInfo *list, int ip, MonoJumpInfoType type, gconstpointer target) MONO_INTERNAL;
-gpointer  mono_resolve_patch_target         (MonoMethod *method, MonoDomain *domain, guint8 *code, MonoJumpInfo *patch_info, gboolean run_cctors) MONO_INTERNAL;
+gpointer  mono_resolve_patch_target         (MonoMethod *method, MonoDomain *domain, guint8 *code, MonoJumpInfo *patch_info, gboolean run_cctors) MONO_LLVM_INTERNAL;
 gpointer  mono_jit_find_compiled_method_with_jit_info (MonoDomain *domain, MonoMethod *method, MonoJitInfo **ji) MONO_INTERNAL;
 gpointer  mono_jit_find_compiled_method     (MonoDomain *domain, MonoMethod *method) MONO_INTERNAL;
 gpointer  mono_jit_compile_method           (MonoMethod *method) MONO_INTERNAL;
@@ -1494,9 +1741,10 @@ gint32    mono_get_lmf_addr_tls_offset      (void) MONO_INTERNAL;
 MonoInst* mono_get_jit_tls_intrinsic        (MonoCompile *cfg) MONO_INTERNAL;
 MonoInst* mono_get_domain_intrinsic         (MonoCompile* cfg) MONO_INTERNAL;
 MonoInst* mono_get_thread_intrinsic         (MonoCompile* cfg) MONO_INTERNAL;
-GList    *mono_varlist_insert_sorted        (MonoCompile *cfg, GList *list, MonoMethodVar *mv, gboolean sort_end) MONO_INTERNAL;
+GList    *mono_varlist_insert_sorted        (MonoCompile *cfg, GList *list, MonoMethodVar *mv, int sort_type) MONO_INTERNAL;
 GList    *mono_varlist_sort                 (MonoCompile *cfg, GList *list, int sort_type) MONO_INTERNAL;
 void      mono_analyze_liveness             (MonoCompile *cfg) MONO_INTERNAL;
+void      mono_analyze_liveness_gc          (MonoCompile *cfg) MONO_INTERNAL;
 void      mono_linear_scan                  (MonoCompile *cfg, GList *vars, GList *regs, regmask_t *used_mask) MONO_INTERNAL;
 void      mono_global_regalloc              (MonoCompile *cfg) MONO_INTERNAL;
 void      mono_create_jump_table            (MonoCompile *cfg, MonoInst *label, MonoBasicBlock **bbs, int num_blocks) MONO_INTERNAL;
@@ -1507,12 +1755,12 @@ MonoJitICallInfo *mono_find_jit_opcode_emulation (int opcode) MONO_INTERNAL;
 void     mono_print_ins_index (int i, MonoInst *ins) MONO_INTERNAL;
 void     mono_print_ins (MonoInst *ins) MONO_INTERNAL;
 gboolean  mini_assembly_can_skip_verification (MonoDomain *domain, MonoMethod *method) MONO_INTERNAL;
-gboolean  mini_method_verify (MonoCompile *cfg, MonoMethod *method) MONO_INTERNAL;
+gboolean mono_compile_is_broken (MonoCompile *cfg, MonoMethod *method, gboolean fail_compile) MONO_INTERNAL;
 MonoInst *mono_get_got_var (MonoCompile *cfg) MONO_INTERNAL;
 void      mono_add_seq_point (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst *ins, int native_offset) MONO_INTERNAL;
 MonoInst* mono_emit_jit_icall (MonoCompile *cfg, gconstpointer func, MonoInst **args) MONO_INTERNAL;
 MonoInst* mono_emit_method_call (MonoCompile *cfg, MonoMethod *method, MonoInst **args, MonoInst *this) MONO_INTERNAL;
-
+void      mono_create_helper_signatures (void) MONO_INTERNAL;
 
 gboolean  mini_class_is_system_array (MonoClass *klass) MONO_INTERNAL;
 MonoMethodSignature *mono_get_element_address_signature (int arity) MONO_INTERNAL;
@@ -1527,8 +1775,35 @@ gint32    mono_linterval_get_intersect_pos  (MonoLiveInterval *i1, MonoLiveInter
 void      mono_linterval_split              (MonoCompile *cfg, MonoLiveInterval *interval, MonoLiveInterval **i1, MonoLiveInterval **i2, int pos) MONO_INTERNAL;
 void      mono_liveness_handle_exception_clauses (MonoCompile *cfg) MONO_INTERNAL;
 
+/* Native Client functions */
+gpointer mono_realloc_native_code(MonoCompile *cfg);
+#ifdef __native_client_codegen__
+void mono_nacl_align_inst(guint8 **pcode, int instlen);
+void mono_nacl_align_call(guint8 **start, guint8 **pcode);
+guint8 *mono_nacl_pad_call(guint8 *code, guint8 ilength);
+guint8 *mono_nacl_align(guint8 *code);
+void mono_nacl_fix_patches(const guint8 *code, MonoJumpInfo *ji);
+/* Defined for each arch */
+guint8 *mono_arch_nacl_pad(guint8 *code, int pad);
+guint8 *mono_arch_nacl_skip_nops(guint8 *code);
+
+extern const guint kNaClAlignment;
+extern const guint kNaClAlignmentMask;
+#endif
+
+#if defined(__native_client__) || defined(__native_client_codegen__)
+void mono_nacl_gc();
+#endif
+
+#if defined(__native_client_codegen__) || defined(__native_client__)
+#define NACL_SIZE(a, b) (b)
+#else
+#define NACL_SIZE(a, b) (a)
+#endif
+
 /* AOT */
 void      mono_aot_init                     (void) MONO_INTERNAL;
+void      mono_aot_cleanup                  (void) MONO_INTERNAL;
 gpointer  mono_aot_get_method               (MonoDomain *domain,
                                                                                         MonoMethod *method) MONO_INTERNAL;
 gpointer  mono_aot_get_method_from_token    (MonoDomain *domain, MonoImage *image, guint32 token) MONO_INTERNAL;
@@ -1542,7 +1817,7 @@ gpointer mono_aot_plt_resolve               (gpointer aot_module, guint32 plt_in
 void     mono_aot_patch_plt_entry (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *addr) MONO_INTERNAL;
 gpointer mono_aot_get_method_from_vt_slot   (MonoDomain *domain, MonoVTable *vtable, int slot) MONO_INTERNAL;
 gpointer mono_aot_create_specific_trampoline   (MonoImage *image, gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len) MONO_INTERNAL;
-gpointer mono_aot_get_named_code            (const char *name) MONO_INTERNAL;
+gpointer mono_aot_get_trampoline            (const char *name) MONO_INTERNAL;
 gpointer mono_aot_get_unbox_trampoline      (MonoMethod *method) MONO_INTERNAL;
 gpointer mono_aot_get_lazy_fetch_trampoline (guint32 slot) MONO_INTERNAL;
 gpointer mono_aot_get_static_rgctx_trampoline (gpointer ctx, gpointer addr) MONO_INTERNAL;
@@ -1550,16 +1825,15 @@ gpointer mono_aot_get_imt_thunk             (MonoVTable *vtable, MonoDomain *dom
 guint8*  mono_aot_get_unwind_info           (MonoJitInfo *ji, guint32 *unwind_info_len) MONO_INTERNAL;
 guint32  mono_aot_method_hash               (MonoMethod *method) MONO_INTERNAL;
 char*    mono_aot_wrapper_name              (MonoMethod *method) MONO_INTERNAL;
-MonoAotTrampInfo* mono_aot_tramp_info_create (const char *name, guint8 *code, guint32 code_len) MONO_INTERNAL;
 MonoMethod* mono_aot_get_array_helper_from_wrapper (MonoMethod *method) MONO_INTERNAL;
-guint32  mono_aot_get_got_offset            (MonoJumpInfo *ji) MONO_INTERNAL;
-char*    mono_aot_get_method_name           (MonoCompile *cfg) MONO_INTERNAL;
-char*    mono_aot_get_plt_symbol            (MonoJumpInfoType type, gconstpointer data) MONO_INTERNAL;
-char*    mono_aot_get_method_debug_name     (MonoCompile *cfg) MONO_INTERNAL;
-MonoJumpInfo* mono_aot_patch_info_dup       (MonoJumpInfo* ji) MONO_INTERNAL;
+guint32  mono_aot_get_got_offset            (MonoJumpInfo *ji) MONO_LLVM_INTERNAL;
+char*    mono_aot_get_method_name           (MonoCompile *cfg) MONO_LLVM_INTERNAL;
+char*    mono_aot_get_plt_symbol            (MonoJumpInfoType type, gconstpointer data) MONO_LLVM_INTERNAL;
+MonoJumpInfo* mono_aot_patch_info_dup       (MonoJumpInfo* ji) MONO_LLVM_INTERNAL;
 void     mono_aot_set_make_unreadable       (gboolean unreadable) MONO_INTERNAL;
 gboolean mono_aot_is_pagefault              (void *ptr) MONO_INTERNAL;
 void     mono_aot_handle_pagefault          (void *ptr) MONO_INTERNAL;
+void     mono_aot_register_jit_icall        (const char *name, gpointer addr) MONO_INTERNAL;
 
 /* This is an exported function */
 void     mono_aot_register_globals          (gpointer *globals);
@@ -1568,17 +1842,18 @@ void     mono_aot_register_module           (gpointer *aot_info);
 
 void     mono_xdebug_init                   (char *xdebug_opts) MONO_INTERNAL;
 void     mono_save_xdebug_info              (MonoCompile *cfg) MONO_INTERNAL;
-void     mono_save_trampoline_xdebug_info   (const char *tramp_name, guint8 *code, guint32 code_size, GSList *unwind_info) MONO_INTERNAL;
+void     mono_save_trampoline_xdebug_info   (MonoTrampInfo *info) MONO_INTERNAL;
 /* This is an exported function */
-void     mono_xdebug_flush                  (void) MONO_INTERNAL;
+void     mono_xdebug_flush                  (void);
 
 /* LLVM backend */
-void     mono_llvm_init                     (void) MONO_INTERNAL;
-void     mono_llvm_cleanup                  (void) MONO_INTERNAL;
-void     mono_llvm_emit_method              (MonoCompile *cfg) MONO_INTERNAL;
-void     mono_llvm_emit_call                (MonoCompile *cfg, MonoCallInst *call) MONO_INTERNAL;
-void     mono_llvm_create_aot_module        (const char *got_symbol) MONO_INTERNAL;
-void     mono_llvm_emit_aot_module          (const char *filename, int got_size) MONO_INTERNAL;
+void     mono_llvm_init                     (void) MONO_LLVM_INTERNAL;
+void     mono_llvm_cleanup                  (void) MONO_LLVM_INTERNAL;
+void     mono_llvm_emit_method              (MonoCompile *cfg) MONO_LLVM_INTERNAL;
+void     mono_llvm_emit_call                (MonoCompile *cfg, MonoCallInst *call) MONO_LLVM_INTERNAL;
+void     mono_llvm_create_aot_module        (const char *got_symbol) MONO_LLVM_INTERNAL;
+void     mono_llvm_emit_aot_module          (const char *filename, int got_size) MONO_LLVM_INTERNAL;
+void     mono_llvm_check_method_supported   (MonoCompile *cfg) MONO_LLVM_INTERNAL;
 
 gboolean  mono_method_blittable             (MonoMethod *method) MONO_INTERNAL;
 gboolean  mono_method_same_domain           (MonoJitInfo *caller, MonoJitInfo *callee) MONO_INTERNAL;
@@ -1591,10 +1866,8 @@ gpointer  mono_create_ftnptr                (MonoDomain *domain, gpointer addr)
 void      mono_replace_ins                  (MonoCompile *cfg, MonoBasicBlock *bb, MonoInst *ins, MonoInst **prev, MonoBasicBlock *first_bb, MonoBasicBlock *last_bb);
 
 int               mono_find_method_opcode      (MonoMethod *method) MONO_INTERNAL;
-MonoJitICallInfo *mono_find_jit_icall_by_name  (const char *name) MONO_INTERNAL;
-MonoJitICallInfo *mono_find_jit_icall_by_addr  (gconstpointer addr) MONO_INTERNAL;
 MonoJitICallInfo *mono_register_jit_icall      (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save) MONO_INTERNAL;
-gconstpointer     mono_icall_get_wrapper       (MonoJitICallInfo* callinfo) MONO_INTERNAL;
+gconstpointer     mono_icall_get_wrapper       (MonoJitICallInfo* callinfo) MONO_LLVM_INTERNAL;
 
 void              mono_trampolines_init (void) MONO_INTERNAL;
 void              mono_trampolines_cleanup (void) MONO_INTERNAL;
@@ -1607,14 +1880,13 @@ gpointer          mono_create_class_init_trampoline (MonoVTable *vtable) MONO_IN
 gpointer          mono_create_generic_class_init_trampoline (void) MONO_INTERNAL;
 gpointer          mono_create_jit_trampoline (MonoMethod *method) MONO_INTERNAL;
 gpointer          mono_create_jit_trampoline_from_token (MonoImage *image, guint32 token) MONO_INTERNAL;
-gpointer          mono_create_jit_trampoline_in_domain (MonoDomain *domain, MonoMethod *method) MONO_INTERNAL;
+gpointer          mono_create_jit_trampoline_in_domain (MonoDomain *domain, MonoMethod *method) MONO_LLVM_INTERNAL;
 gpointer          mono_create_delegate_trampoline (MonoClass *klass) MONO_INTERNAL;
 gpointer          mono_create_rgctx_lazy_fetch_trampoline (guint32 offset) MONO_INTERNAL;
 gpointer          mono_create_monitor_enter_trampoline (void) MONO_INTERNAL;
 gpointer          mono_create_monitor_exit_trampoline (void) MONO_INTERNAL;
 gpointer          mono_create_static_rgctx_trampoline (MonoMethod *m, gpointer addr) MONO_INTERNAL;
-gpointer          mono_create_llvm_vcall_trampoline (MonoMethod *method) MONO_INTERNAL;
-gpointer          mono_create_llvm_imt_trampoline (MonoDomain *domain, MonoMethod *m, int vt_offset) MONO_INTERNAL;
+gpointer          mono_create_llvm_imt_trampoline (MonoDomain *domain, MonoMethod *m, int vt_offset) MONO_LLVM_INTERNAL;
 MonoVTable*       mono_find_class_init_trampoline_by_addr (gconstpointer addr) MONO_INTERNAL;
 guint32           mono_find_rgctx_lazy_fetch_trampoline_by_addr (gconstpointer addr) MONO_INTERNAL;
 gpointer          mono_magic_trampoline (mgreg_t *regs, guint8 *code, gpointer arg, guint8* tramp) MONO_INTERNAL;
@@ -1630,10 +1902,14 @@ void              mono_monitor_enter_trampoline (mgreg_t *regs, guint8 *code, Mo
 void              mono_monitor_exit_trampoline (mgreg_t *regs, guint8 *code, MonoObject *obj, guint8 *tramp) MONO_INTERNAL;
 gconstpointer     mono_get_trampoline_func (MonoTrampolineType tramp_type);
 gpointer          mini_get_vtable_trampoline (int slot_index) MONO_INTERNAL;
-gpointer*         mono_get_vcall_slot_addr (guint8* code, mgreg_t *regs) MONO_INTERNAL;
+char*             mono_get_generic_trampoline_name (MonoTrampolineType tramp_type) MONO_INTERNAL;
+char*             mono_get_rgctx_fetch_trampoline_name (int slot) MONO_INTERNAL;
 
 gboolean          mono_running_on_valgrind (void) MONO_INTERNAL;
 void*             mono_global_codeman_reserve (int size) MONO_INTERNAL;
+void*             nacl_global_codeman_get_dest(void *data) MONO_INTERNAL;
+void              mono_global_codeman_commit(void *data, int size, int newsize) MONO_INTERNAL;
+void              nacl_global_codeman_validate(guint8 **buf_base, int buf_size, guint8 **code_end) MONO_INTERNAL;
 const char       *mono_regname_full (int reg, int bank) MONO_INTERNAL;
 gint32*           mono_allocate_stack_slots_full (MonoCompile *cfg, gboolean backward, guint32 *stack_size, guint32 *stack_align) MONO_INTERNAL;
 gint32*           mono_allocate_stack_slots (MonoCompile *cfg, guint32 *stack_size, guint32 *stack_align) MONO_INTERNAL;
@@ -1642,7 +1918,7 @@ MonoInst         *mono_branch_optimize_exception_target (MonoCompile *cfg, MonoB
 void              mono_remove_critical_edges (MonoCompile *cfg) MONO_INTERNAL;
 gboolean          mono_is_regsize_var (MonoType *t) MONO_INTERNAL;
 void              mini_emit_memcpy (MonoCompile *cfg, int destreg, int doffset, int srcreg, int soffset, int size, int align) MONO_INTERNAL;
-CompRelation      mono_opcode_to_cond (int opcode) MONO_INTERNAL;
+CompRelation      mono_opcode_to_cond (int opcode) MONO_LLVM_INTERNAL;
 CompType          mono_opcode_to_type (int opcode, int cmp_opcode) MONO_INTERNAL;
 CompRelation      mono_negate_cond (CompRelation cond) MONO_INTERNAL;
 int               mono_op_imm_to_op (int opcode) MONO_INTERNAL;
@@ -1654,6 +1930,8 @@ MonoUnwindOp     *mono_create_unwind_op (int when,
 void              mono_emit_unwind_op (MonoCompile *cfg, int when, 
                                                                           int tag, int reg, 
                                                                           int val) MONO_INTERNAL;
+MonoTrampInfo*    mono_tramp_info_create (const char *name, guint8 *code, guint32 code_size, MonoJumpInfo *ji, GSList *unwind_ops) MONO_INTERNAL;
+void              mono_tramp_info_free (MonoTrampInfo *info) MONO_INTERNAL;
 
 int               mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_bblock, MonoBasicBlock *end_bblock, 
                                                                         MonoInst *return_var, GList *dont_inline, MonoInst **inline_args, 
@@ -1678,25 +1956,16 @@ void     *mono_arch_instrument_prolog           (MonoCompile *cfg, void *func, v
 void     *mono_arch_instrument_epilog           (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments) MONO_INTERNAL;
 void     *mono_arch_instrument_epilog_full     (MonoCompile *cfg, void *func, void *p, gboolean enable_arguments, gboolean preserve_argument_registers) MONO_INTERNAL;
 void      mono_codegen                          (MonoCompile *cfg) MONO_INTERNAL;
-void      mono_call_inst_add_outarg_reg         (MonoCompile *cfg, MonoCallInst *call, int vreg, int hreg, gboolean fp) MONO_INTERNAL;
+void      mono_call_inst_add_outarg_reg         (MonoCompile *cfg, MonoCallInst *call, int vreg, int hreg, int bank) MONO_LLVM_INTERNAL;
 const char *mono_arch_regname                   (int reg) MONO_INTERNAL;
 const char *mono_arch_fregname                  (int reg) MONO_INTERNAL;
-gpointer  mono_arch_get_throw_exception         (void) MONO_INTERNAL;
-gpointer  mono_arch_get_rethrow_exception       (void) MONO_INTERNAL;
-gpointer  mono_arch_get_throw_exception_by_name (void) MONO_INTERNAL;
-gpointer  mono_arch_get_throw_corlib_exception  (void) MONO_INTERNAL;
 void      mono_arch_exceptions_init             (void) MONO_INTERNAL;
-guchar*   mono_arch_create_trampoline_code      (MonoTrampolineType tramp_type) MONO_INTERNAL;
-guchar*   mono_arch_create_trampoline_code_full (MonoTrampolineType tramp_type, guint32 *code_size, MonoJumpInfo **ji, GSList **out_unwind_ops, gboolean aot) MONO_INTERNAL;
-gpointer  mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot) MONO_INTERNAL;
-gpointer  mono_arch_create_rgctx_lazy_fetch_trampoline_full (guint32 slot, guint32 *code_size, MonoJumpInfo **ji, gboolean aot) MONO_INTERNAL;
-gpointer  mono_arch_create_generic_class_init_trampoline (void) MONO_INTERNAL;
-gpointer  mono_arch_get_nullified_class_init_trampoline (guint32 *code_len) MONO_INTERNAL;
-gpointer  mono_arch_create_monitor_enter_trampoline (void) MONO_INTERNAL;
-gpointer  mono_arch_create_monitor_exit_trampoline (void) MONO_INTERNAL;
-gpointer  mono_arch_create_monitor_enter_trampoline_full (guint32 *code_size, MonoJumpInfo **ji, gboolean aot) MONO_INTERNAL;
-gpointer  mono_arch_create_monitor_exit_trampoline_full (guint32 *code_size, MonoJumpInfo **ji, gboolean aot) MONO_INTERNAL;
-gpointer  mono_arch_create_generic_class_init_trampoline_full (guint32 *code_size, MonoJumpInfo **ji, gboolean aot) MONO_INTERNAL;
+guchar*   mono_arch_create_generic_trampoline   (MonoTrampolineType tramp_type, MonoTrampInfo **info, gboolean aot) MONO_INTERNAL;
+gpointer  mono_arch_create_rgctx_lazy_fetch_trampoline (guint32 slot, MonoTrampInfo **info, gboolean aot) MONO_INTERNAL;
+gpointer  mono_arch_create_generic_class_init_trampoline (MonoTrampInfo **info, gboolean aot) MONO_INTERNAL;
+gpointer  mono_arch_get_nullified_class_init_trampoline (MonoTrampInfo **info) MONO_INTERNAL;
+gpointer  mono_arch_create_monitor_enter_trampoline (MonoTrampInfo **info, gboolean aot) MONO_INTERNAL;
+gpointer  mono_arch_create_monitor_exit_trampoline (MonoTrampInfo **info, gboolean aot) MONO_INTERNAL;
 GList    *mono_arch_get_allocatable_int_vars    (MonoCompile *cfg) MONO_INTERNAL;
 GList    *mono_arch_get_global_int_regs         (MonoCompile *cfg) MONO_INTERNAL;
 GList    *mono_arch_get_global_fp_regs          (MonoCompile *cfg) MONO_INTERNAL;
@@ -1731,10 +2000,11 @@ MonoInst *mono_arch_emit_inst_for_method        (MonoCompile *cfg, MonoMethod *c
 void      mono_arch_decompose_opts              (MonoCompile *cfg, MonoInst *ins) MONO_INTERNAL;
 void      mono_arch_decompose_long_opts         (MonoCompile *cfg, MonoInst *ins) MONO_INTERNAL;
 GSList*   mono_arch_get_delegate_invoke_impls   (void) MONO_INTERNAL;
-LLVMCallInfo* mono_arch_get_llvm_call_info      (MonoCompile *cfg, MonoMethodSignature *sig) MONO_INTERNAL;
+LLVMCallInfo* mono_arch_get_llvm_call_info      (MonoCompile *cfg, MonoMethodSignature *sig) MONO_LLVM_INTERNAL;
 guint8*   mono_arch_emit_load_got_addr          (guint8 *start, guint8 *code, MonoCompile *cfg, MonoJumpInfo **ji) MONO_INTERNAL;
 guint8*   mono_arch_emit_load_aotconst          (guint8 *start, guint8 *code, MonoJumpInfo **ji, int tramp_type, gconstpointer target) MONO_INTERNAL;
 GSList*   mono_arch_get_cie_program             (void) MONO_INTERNAL;
+void      mono_arch_set_target                  (char *mtriple) MONO_INTERNAL;
 
 /* Soft Debug support */
 #ifdef MONO_ARCH_SOFT_DEBUG_SUPPORTED
@@ -1749,30 +2019,22 @@ guint8*   mono_arch_get_ip_for_breakpoint       (MonoJitInfo *ji, MonoContext *c
 void     mono_arch_skip_breakpoint              (MonoContext *ctx) MONO_INTERNAL;
 void     mono_arch_skip_single_step             (MonoContext *ctx) MONO_INTERNAL;
 gpointer mono_arch_get_seq_point_info           (MonoDomain *domain, guint8 *code) MONO_INTERNAL;
+void     mono_arch_setup_resume_sighandler_ctx  (MonoContext *ctx, gpointer func) MONO_INTERNAL;
 #endif
 
-MonoJitInfo *mono_arch_find_jit_info            (MonoDomain *domain, 
-                                                MonoJitTlsData *jit_tls, 
-                                                MonoJitInfo *res, 
-                                                MonoJitInfo *prev_ji, 
-                                                MonoContext *ctx, 
-                                                MonoContext *new_ctx, 
-                                                MonoLMF **lmf, 
-                                                gboolean *managed) MONO_INTERNAL;
 gboolean
-mono_arch_find_jit_info_ext (MonoDomain *domain, MonoJitTlsData *jit_tls, 
-                                                        MonoJitInfo *ji, MonoContext *ctx, 
-                                                        MonoContext *new_ctx, MonoLMF **lmf, 
-                                                        StackFrameInfo *frame_info) MONO_INTERNAL;
-gpointer mono_arch_get_call_filter              (void) MONO_INTERNAL;
-gpointer mono_arch_get_restore_context          (void) MONO_INTERNAL;
-gpointer mono_arch_get_call_filter_full         (guint32 *code_size, MonoJumpInfo **ji, gboolean aot) MONO_INTERNAL;
-gpointer mono_arch_get_restore_context_full     (guint32 *code_size, MonoJumpInfo **ji, gboolean aot) MONO_INTERNAL;
-gpointer  mono_arch_get_throw_exception_full    (guint32 *code_size, MonoJumpInfo **ji, gboolean aot) MONO_INTERNAL;
-gpointer  mono_arch_get_rethrow_exception_full  (guint32 *code_size, MonoJumpInfo **ji, gboolean aot) MONO_INTERNAL;
-gpointer  mono_arch_get_throw_exception_by_name_full (guint32 *code_size, MonoJumpInfo **ji, gboolean aot) MONO_INTERNAL;
-gpointer  mono_arch_get_throw_corlib_exception_full (guint32 *code_size, MonoJumpInfo **ji, gboolean aot) MONO_INTERNAL;
-gpointer  mono_arch_get_throw_pending_exception_full (guint32 *code_size, MonoJumpInfo **ji, gboolean aot) MONO_INTERNAL;
+mono_arch_find_jit_info (MonoDomain *domain, MonoJitTlsData *jit_tls, 
+                                                MonoJitInfo *ji, MonoContext *ctx, 
+                                                MonoContext *new_ctx, MonoLMF **lmf,
+                                                mgreg_t **save_locations,
+                                                StackFrameInfo *frame_info) MONO_INTERNAL;
+gpointer  mono_arch_get_throw_exception_by_name (void) MONO_INTERNAL;
+gpointer mono_arch_get_call_filter              (MonoTrampInfo **info, gboolean aot) MONO_INTERNAL;
+gpointer mono_arch_get_restore_context          (MonoTrampInfo **info, gboolean aot) MONO_INTERNAL;
+gpointer  mono_arch_get_throw_exception         (MonoTrampInfo **info, gboolean aot) MONO_INTERNAL;
+gpointer  mono_arch_get_rethrow_exception       (MonoTrampInfo **info, gboolean aot) MONO_INTERNAL;
+gpointer  mono_arch_get_throw_corlib_exception  (MonoTrampInfo **info, gboolean aot) MONO_INTERNAL;
+gpointer  mono_arch_get_throw_pending_exception (MonoTrampInfo **info, gboolean aot) MONO_INTERNAL;
 gboolean mono_arch_handle_exception             (void *sigctx, gpointer obj, gboolean test_only) MONO_INTERNAL;
 void     mono_arch_handle_altstack_exception    (void *sigctx, gpointer fault_addr, gboolean stack_ovf) MONO_INTERNAL;
 gboolean mono_handle_soft_stack_ovf             (MonoJitTlsData *jit_tls, MonoJitInfo *ji, void *ctx, guint8* fault_addr) MONO_INTERNAL;
@@ -1786,20 +2048,19 @@ MonoInst* mono_arch_get_domain_intrinsic        (MonoCompile* cfg) MONO_INTERNAL
 gboolean mono_arch_is_int_overflow              (void *sigctx, void *info) MONO_INTERNAL;
 void     mono_arch_invalidate_method            (MonoJitInfo *ji, void *func, gpointer func_arg) MONO_INTERNAL;
 guint32  mono_arch_get_patch_offset             (guint8 *code) MONO_INTERNAL;
-gpointer mono_arch_get_vcall_slot               (guint8 *code, mgreg_t *regs, int *displacement) MONO_INTERNAL;
 gpointer*mono_arch_get_delegate_method_ptr_addr (guint8* code, mgreg_t *regs) MONO_INTERNAL;
 void     mono_arch_create_vars                  (MonoCompile *cfg) MONO_INTERNAL;
 void     mono_arch_save_unwind_info             (MonoCompile *cfg) MONO_INTERNAL;
 void     mono_arch_register_lowlevel_calls      (void) MONO_INTERNAL;
-gpointer mono_arch_get_unbox_trampoline         (MonoGenericSharingContext *gsctx, MonoMethod *m, gpointer addr) MONO_INTERNAL;
+gpointer mono_arch_get_unbox_trampoline         (MonoMethod *m, gpointer addr) MONO_INTERNAL;
 gpointer mono_arch_get_static_rgctx_trampoline  (MonoMethod *m, MonoMethodRuntimeGenericContext *mrgctx, gpointer addr) MONO_INTERNAL;
 gpointer  mono_arch_get_llvm_imt_trampoline     (MonoDomain *domain, MonoMethod *method, int vt_offset) MONO_INTERNAL;
 void     mono_arch_patch_callsite               (guint8 *method_start, guint8 *code, guint8 *addr) MONO_INTERNAL;
 void     mono_arch_patch_plt_entry              (guint8 *code, gpointer *got, mgreg_t *regs, guint8 *addr) MONO_INTERNAL;
 void     mono_arch_nullify_class_init_trampoline(guint8 *code, mgreg_t *regs) MONO_INTERNAL;
 void     mono_arch_nullify_plt_entry            (guint8 *code, mgreg_t *regs) MONO_INTERNAL;
-int      mono_arch_get_this_arg_reg             (MonoMethodSignature *sig, MonoGenericSharingContext *gsctx, guint8 *code) MONO_INTERNAL;
-gpointer mono_arch_get_this_arg_from_call       (MonoGenericSharingContext *gsctx, MonoMethodSignature *sig, mgreg_t *regs, guint8 *code) MONO_INTERNAL;
+int      mono_arch_get_this_arg_reg             (guint8 *code) MONO_INTERNAL;
+gpointer mono_arch_get_this_arg_from_call       (mgreg_t *regs, guint8 *code) MONO_INTERNAL;
 gpointer mono_arch_get_delegate_invoke_impl     (MonoMethodSignature *sig, gboolean has_target) MONO_INTERNAL;
 gpointer mono_arch_create_specific_trampoline   (gpointer arg1, MonoTrampolineType tramp_type, MonoDomain *domain, guint32 *code_len) MONO_INTERNAL;
 void        mono_arch_emit_imt_argument         (MonoCompile *cfg, MonoCallInst *call, MonoInst *imt_arg) MONO_INTERNAL;
@@ -1807,6 +2068,9 @@ MonoMethod* mono_arch_find_imt_method           (mgreg_t *regs, guint8 *code) MO
 MonoVTable* mono_arch_find_static_call_vtable   (mgreg_t *regs, guint8 *code) MONO_INTERNAL;
 gpointer    mono_arch_build_imt_thunk           (MonoVTable *vtable, MonoDomain *domain, MonoIMTCheckItem **imt_entries, int count, gpointer fail_tramp) MONO_INTERNAL;
 void    mono_arch_notify_pending_exc            (void) MONO_INTERNAL;
+guint8* mono_arch_get_call_target               (guint8 *code) MONO_INTERNAL;
+guint32 mono_arch_get_plt_info_offset           (guint8 *plt_entry, mgreg_t *regs, guint8 *code) MONO_INTERNAL;
+GSList *mono_arch_get_trampolines               (gboolean aot) MONO_INTERNAL;
 
 /* Handle block guard */
 gpointer mono_arch_install_handler_block_guard (MonoJitInfo *ji, MonoJitExceptionInfo *clause, MonoContext *ctx, gpointer new_value) MONO_INTERNAL;
@@ -1816,7 +2080,6 @@ gboolean mono_install_handler_block_guard (MonoInternalThread *thread, MonoConte
 
 /* Exception handling */
 
-/* Same as MonoStackWalk, but pass the context/frame type as well */
 typedef gboolean (*MonoJitStackWalk)            (StackFrameInfo *frame, MonoContext *ctx, gpointer data);
 
 void     mono_exceptions_init                   (void) MONO_INTERNAL;
@@ -1827,12 +2090,12 @@ void     mono_print_thread_dump                 (void *sigctx);
 void     mono_print_thread_dump_from_ctx        (MonoContext *ctx);
 void     mono_jit_walk_stack                    (MonoStackWalk func, gboolean do_il_offset, gpointer user_data) MONO_INTERNAL;
 void     mono_jit_walk_stack_from_ctx           (MonoStackWalk func, MonoContext *ctx, gboolean do_il_offset, gpointer user_data) MONO_INTERNAL;
-void     mono_jit_walk_stack_from_ctx_in_thread (MonoJitStackWalk func, MonoDomain *domain, MonoContext *start_ctx, gboolean do_il_offset, MonoInternalThread *thread, MonoLMF *lmf, gpointer user_data) MONO_INTERNAL;
+void     mono_walk_stack                        (MonoJitStackWalk func, MonoDomain *domain, MonoContext *start_ctx, gboolean do_il_offset, MonoInternalThread *thread, MonoLMF *lmf, gpointer user_data) MONO_INTERNAL;
 void     mono_setup_altstack                    (MonoJitTlsData *tls) MONO_INTERNAL;
 void     mono_free_altstack                     (MonoJitTlsData *tls) MONO_INTERNAL;
 gpointer mono_altstack_restore_prot             (mgreg_t *regs, guint8 *code, gpointer *tramp_data, guint8* tramp) MONO_INTERNAL;
 MonoJitInfo* mini_jit_info_table_find           (MonoDomain *domain, char *addr, MonoDomain **out_domain) MONO_INTERNAL;
-void     mono_resume_unwind                     (void) MONO_INTERNAL;
+void     mono_resume_unwind                     (MonoContext *ctx) MONO_LLVM_INTERNAL;
 
 MonoJitInfo * mono_find_jit_info                (MonoDomain *domain, MonoJitTlsData *jit_tls, MonoJitInfo *res, MonoJitInfo *prev_ji, MonoContext *ctx, MonoContext *new_ctx, char **trace, MonoLMF **lmf, int *native_offset, gboolean *managed) MONO_INTERNAL;
 
@@ -1840,6 +2103,7 @@ gboolean
 mono_find_jit_info_ext (MonoDomain *domain, MonoJitTlsData *jit_tls, 
                                                MonoJitInfo *prev_ji, MonoContext *ctx,
                                                MonoContext *new_ctx, char **trace, MonoLMF **lmf,
+                                               mgreg_t **save_locations,
                                                StackFrameInfo *frame) MONO_INTERNAL;
 
 gpointer mono_get_throw_exception               (void) MONO_INTERNAL;
@@ -1849,10 +2113,6 @@ gpointer mono_get_restore_context               (void) MONO_INTERNAL;
 gpointer mono_get_throw_exception_by_name       (void) MONO_INTERNAL;
 gpointer mono_get_throw_corlib_exception        (void) MONO_INTERNAL;
 
-/* the new function to do stack walks */
-typedef gboolean (*MonoStackFrameWalk)          (MonoDomain *domain, MonoContext *ctx, MonoJitInfo *ji, gpointer data);
-void      mono_walk_stack                       (MonoDomain *domain, MonoJitTlsData *jit_tls, MonoContext *start_ctx, MonoStackFrameWalk func, gpointer user_data);
-
 MonoArray *ves_icall_get_trace                  (MonoException *exc, gint32 skip, MonoBoolean need_file_info) MONO_INTERNAL;
 MonoBoolean ves_icall_get_frame_info            (gint32 skip, MonoBoolean need_file_info, 
                                                 MonoReflectionMethod **method, 
@@ -1881,6 +2141,7 @@ void      mono_debug_init_method                (MonoCompile *cfg, MonoBasicBloc
                                                 guint32 breakpoint_id) MONO_INTERNAL;
 void      mono_debug_open_method                (MonoCompile *cfg) MONO_INTERNAL;
 void      mono_debug_close_method               (MonoCompile *cfg) MONO_INTERNAL;
+void      mono_debug_free_method                (MonoCompile *cfg) MONO_INTERNAL;
 void      mono_debug_open_block                 (MonoCompile *cfg, MonoBasicBlock *bb, guint32 address) MONO_INTERNAL;
 void      mono_debug_record_line_number         (MonoCompile *cfg, MonoInst *ins, guint32 address) MONO_INTERNAL;
 void      mono_debug_serialize_debug_info       (MonoCompile *cfg, guint8 **out_buf, guint32 *buf_len) MONO_INTERNAL;
@@ -1995,6 +2256,7 @@ gpointer mono_helper_get_rgctx_other_ptr (MonoClass *caller_class, MonoVTable *v
                                          gint32 rgctx_index) MONO_INTERNAL;
 
 void mono_generic_sharing_init (void) MONO_INTERNAL;
+void mono_generic_sharing_cleanup (void) MONO_INTERNAL;
 
 MonoClass* mini_class_get_container_class (MonoClass *class) MONO_INTERNAL;
 MonoGenericContext* mini_class_get_context (MonoClass *class) MONO_INTERNAL;
@@ -2011,6 +2273,8 @@ guint mono_type_to_regmove (MonoCompile *cfg, MonoType *type) MONO_INTERNAL;
 
 void mono_cfg_add_try_hole (MonoCompile *cfg, MonoExceptionClause *clause, guint8 *start, MonoBasicBlock *bb) MONO_INTERNAL;
 
+void mono_cfg_set_exception (MonoCompile *cfg, int type) MONO_INTERNAL;
+
 /* wapihandles.c */
 int mini_wapi_hps (int argc, char **argv) MONO_INTERNAL;
 
@@ -2074,10 +2338,12 @@ void        mono_simd_intrinsics_init (void) MONO_INTERNAL;
 void mono_enable_jit_map (void) MONO_INTERNAL;
 void mono_emit_jit_map   (MonoJitInfo *jinfo) MONO_INTERNAL;
 void mono_emit_jit_tramp (void *start, int size, const char *desc) MONO_INTERNAL;
+gboolean mono_jit_map_is_enabled (void) MONO_INTERNAL;
 #else
 #define mono_enable_jit_map()
 #define mono_emit_jit_map(ji)
 #define mono_emit_jit_tramp(s,z,d)
+#define mono_jit_map_is_enabled() (0)
 #endif
 
 /*
@@ -2142,6 +2408,8 @@ enum {
        MONO_AOT_WRAPPER_MONO_ENTER,
        MONO_AOT_WRAPPER_MONO_EXIT,
        MONO_AOT_WRAPPER_ELEMENT_ADDR,
+       MONO_AOT_WRAPPER_PTR_TO_STRUCTURE,
+       MONO_AOT_WRAPPER_STRUCTURE_TO_PTR,
        MONO_AOT_WRAPPER_LAST
 };