[profiler] Implement call context introspection for enter/leave events.
[mono.git] / mono / mini / mini.h
index c9a18e873622329602f8b2d26a54817fe8a52d91..7d681122d43c3b3aa212a18cc74e77f265966a02 100644 (file)
 #include "mono/metadata/security-manager.h"
 #include "mono/metadata/exception.h"
 
-#ifdef __native_client_codegen__
-#include <nacl/nacl_dyncode.h>
-#endif
-
-
 /*
  * The mini code should not have any compile time dependencies on the GC being used, so the same object file from mini/
  * can be linked into both mono and mono-sgen.
@@ -760,6 +755,9 @@ struct MonoBasicBlock {
        /* List of call sites in this bblock sorted by pc_offset */
        GSList *gc_callsites;
 
+       /* If this is not null, the basic block is a try hole for this clause */
+       MonoExceptionClause *clause_hole;
+
        /*
         * The region encodes whether the basic block is inside
         * a finally, catch, filter or none of these.
@@ -1172,10 +1170,6 @@ typedef struct {
        MonoContext     ex_ctx;
        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. 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;
@@ -1217,11 +1211,12 @@ typedef struct {
         */
        gpointer abort_exc_stack_threshold;
 
-
        /*
         * List of methods being JIT'd in the current thread.
         */
        int active_jit_methods;
+
+       gpointer interp_context;
 } MonoJitTlsData;
 
 /*
@@ -1490,7 +1485,6 @@ typedef enum {
        MONO_TRAMPOLINE_RESTORE_STACK_PROT,
        MONO_TRAMPOLINE_GENERIC_VIRTUAL_REMOTING,
        MONO_TRAMPOLINE_VCALL,
-       MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD,
        MONO_TRAMPOLINE_NUM
 } MonoTrampolineType;
 
@@ -1501,7 +1495,7 @@ typedef enum {
 
 /* These trampolines receive an argument directly in a register */
 #define MONO_TRAMPOLINE_TYPE_HAS_ARG(t)                \
-       ((t) == MONO_TRAMPOLINE_HANDLER_BLOCK_GUARD)
+       (FALSE)
 
 /* optimization flags */
 #define OPTFLAG(id,shift,name,descr) MONO_OPT_ ## id = 1 << shift,
@@ -1639,10 +1633,18 @@ typedef struct {
 
        /* A hashtable of region ID-> SP var mappings */
        /* An SP var is a place to store the stack pointer (used by handlers)*/
+       /*
+        * FIXME We can potentially get rid of this, since it was mainly used
+        * for hijacking return address for handler.
+        */
        GHashTable      *spvars;
 
-       /* A hashtable of region ID -> EX var mappings */
-       /* An EX var stores the exception object passed to catch/filter blocks */
+       /*
+        * A hashtable of region ID -> EX var mappings
+        * An EX var stores the exception object passed to catch/filter blocks
+        * For finally blocks, it is set to TRUE if we should throw an abort
+        * once the execution of the finally block is over.
+        */
        GHashTable      *exvars;
 
        GList           *ldstr_list; /* used by AOT */
@@ -1678,11 +1680,6 @@ typedef struct {
        MonoInst *stack_inbalance_var;
 
        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;
@@ -1691,7 +1688,6 @@ typedef struct {
        guint            epilog_end;
        regmask_t        used_int_regs;
        guint32          opt;
-       guint32          prof_options;
        guint32          flags;
        guint32          comp_done;
        guint32          verbose_level;
@@ -1770,7 +1766,7 @@ typedef struct {
        gpointer         debug_info;
        guint32          lmf_offset;
     guint16          *intvars;
-       MonoProfileCoverageInfo *coverage_info;
+       MonoProfilerCoverageInfo *coverage_info;
        GHashTable       *token_info_hash;
        MonoCompileArch  arch;
        guint32          inline_depth;
@@ -1920,8 +1916,13 @@ typedef struct {
        int stat_inlineable_methods;
        int stat_inlined_methods;
        int stat_code_reallocs;
+
+       MonoProfilerCallInstrumentationFlags prof_flags;
 } MonoCompile;
 
+#define MONO_CFG_PROFILE_CALL_CONTEXT(cfg) \
+       ((cfg)->prof_flags & (MONO_PROFILER_CALL_INSTRUMENTATION_PROLOGUE_CONTEXT | MONO_PROFILER_CALL_INSTRUMENTATION_EPILOGUE_CONTEXT))
+
 typedef enum {
        MONO_CFG_HAS_ALLOCA = 1 << 0,
        MONO_CFG_HAS_CALLS  = 1 << 1,
@@ -2356,7 +2357,14 @@ MonoDomain* mini_init                      (const char *filename, const char *ru
 void        mini_cleanup                   (MonoDomain *domain);
 MONO_API MonoDebugOptions *mini_get_debug_options   (void);
 MONO_API gboolean    mini_parse_debug_option (const char *option);
-void        mini_profiler_enable_with_options (const char *profile_options);
+void        mini_add_profiler_argument (const char *desc);
+void        mini_profiler_emit_instrumentation_call (MonoCompile *cfg, void *func, gboolean entry, MonoInst **ret, MonoType *rtype);
+void        mini_profiler_context_enable (void);
+gpointer    mini_profiler_context_get_this (MonoProfilerCallContext *ctx);
+gpointer    mini_profiler_context_get_argument (MonoProfilerCallContext *ctx, guint32 pos);
+gpointer    mini_profiler_context_get_local (MonoProfilerCallContext *ctx, guint32 pos);
+gpointer    mini_profiler_context_get_result (MonoProfilerCallContext *ctx);
+void        mini_profiler_context_free_buffer (gpointer buffer);
 
 /* graph dumping */
 void mono_cfg_dump_create_context (MonoCompile *cfg);
@@ -2481,6 +2489,7 @@ MonoInst* mono_emit_jit_icall_by_info (MonoCompile *cfg, int il_offset, MonoJitI
 MonoInst* mono_emit_method_call (MonoCompile *cfg, MonoMethod *method, MonoInst **args, MonoInst *this_ins);
 void      mono_create_helper_signatures (void);
 MonoInst* mono_emit_native_call (MonoCompile *cfg, gconstpointer func, MonoMethodSignature *sig, MonoInst **args);
+gboolean  mini_should_insert_breakpoint (MonoMethod *method);
 
 gboolean  mini_class_is_system_array (MonoClass *klass);
 MonoMethodSignature *mono_get_element_address_signature (int arity);
@@ -2498,12 +2507,6 @@ void      mono_liveness_handle_exception_clauses (MonoCompile *cfg);
 /* Native Client functions */
 gpointer mono_realloc_native_code(MonoCompile *cfg);
 
-#if defined(__native_client__) || defined(__native_client_codegen__)
-extern volatile int __nacl_thread_suspension_needed;
-void __nacl_suspend_thread_if_needed(void);
-void mono_nacl_gc(void);
-#endif
-
 extern MonoDebugOptions debug_options;
 
 static inline MonoMethod*
@@ -2812,6 +2815,9 @@ gboolean  mono_arch_is_breakpoint_event         (void *info, void *sigctx);
 void     mono_arch_skip_breakpoint              (MonoContext *ctx, MonoJitInfo *ji);
 void     mono_arch_skip_single_step             (MonoContext *ctx);
 gpointer mono_arch_get_seq_point_info           (MonoDomain *domain, guint8 *code);
+#endif
+
+#ifdef MONO_ARCH_HAVE_INIT_LMF_EXT
 void     mono_arch_init_lmf_ext                 (MonoLMFExt *ext, gpointer prev_lmf);
 #endif
 
@@ -2865,12 +2871,6 @@ guint32 mono_arch_get_plt_info_offset           (guint8 *plt_entry, mgreg_t *reg
 GSList *mono_arch_get_trampolines               (gboolean aot);
 gpointer mono_arch_get_enter_icall_trampoline   (MonoTrampInfo **info);
 
-/* Handle block guard */
-gpointer mono_arch_install_handler_block_guard (MonoJitInfo *ji, MonoJitExceptionInfo *clause, MonoContext *ctx, gpointer new_value);
-gpointer mono_arch_create_handler_block_trampoline (MonoTrampInfo **info, gboolean aot);
-gpointer mono_create_handler_block_trampoline (void);
-gboolean mono_install_handler_block_guard (MonoThreadUnwindState *ctx);
-
 /*New interruption machinery */
 void
 mono_setup_async_callback (MonoContext *ctx, void (*async_cb)(void *fun), gpointer user_data);