Use new atomis with allocated_heap.
[mono.git] / mono / metadata / domain-internals.h
index 26ea5cde7ec2b1a401b7befcb8d0630c265d2b17..f9bf57a3207f89003d812fce44540435852feb0b 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Appdomain-related internal data structures and functions.
+ * Copyright 2012 Xamarin Inc (http://www.xamarin.com)
  */
 #ifndef __MONO_METADATA_DOMAIN_INTERNALS_H__
 #define __MONO_METADATA_DOMAIN_INTERNALS_H__
@@ -8,10 +9,11 @@
 #include <mono/metadata/mempool.h>
 #include <mono/metadata/lock-tracer.h>
 #include <mono/utils/mono-codeman.h>
-#include <mono/utils/mono-hash.h>
+#include <mono/metadata/mono-hash.h>
 #include <mono/utils/mono-compiler.h>
 #include <mono/utils/mono-internal-hash.h>
 #include <mono/io-layer/io-layer.h>
+#include <mono/metadata/mempool-internals.h>
 
 extern CRITICAL_SECTION mono_delegate_section;
 extern CRITICAL_SECTION mono_strtod_mutex;
@@ -84,6 +86,7 @@ typedef struct {
        union {
                MonoClass *catch_class;
                gpointer filter;
+               gpointer handler_end;
        } data;
 } MonoJitExceptionInfo;
 
@@ -95,15 +98,78 @@ typedef struct {
        int dummy;
 } MonoGenericSharingContext;
 
+/* Simplified DWARF location list entry */
+typedef struct {
+       /* Whenever the value is in a register */
+       gboolean is_reg;
+       /*
+        * If is_reg is TRUE, the register which contains the value. Otherwise
+        * the base register.
+        */
+       int reg;
+       /*
+        * If is_reg is FALSE, the offset of the stack location relative to 'reg'.
+        * Otherwise, 0.
+        */
+       int offset;
+       /*
+        * Offsets of the PC interval where the value is in this location.
+        */
+       int from, to;
+} MonoDwarfLocListEntry;
+
 typedef struct
 {
        MonoGenericSharingContext *generic_sharing_context;
+       int nlocs;
+       MonoDwarfLocListEntry *locations;
        gint32 this_offset;
        guint8 this_reg;
        gboolean has_this:1;
        gboolean this_in_reg:1;
 } MonoGenericJitInfo;
 
+/*
+A try block hole is used to represent a non-contiguous part of
+of a segment of native code protected by a given .try block.
+Usually, a try block is defined as a contiguous segment of code.
+But in some cases it's needed to have some parts of it to not be protected.
+For example, given "try {} finally {}", the code in the .try block to call
+the finally part looks like:
+
+try {
+    ...
+       call finally_block
+       adjust stack
+       jump outside try block
+       ...
+} finally {
+       ...
+}
+
+The instructions between the call and the jump should not be under the try block since they happen
+after the finally block executes, which means if an async exceptions happens at that point we would
+execute the finally clause twice. So, to avoid this, we introduce a hole in the try block to signal
+that those instructions are not protected.
+*/
+typedef struct
+{
+       guint32 offset;
+       guint16 clause;
+       guint16 length;
+} MonoTryBlockHoleJitInfo;
+
+typedef struct
+{
+       guint16 num_holes;
+       MonoTryBlockHoleJitInfo holes [MONO_ZERO_LEN_ARRAY];
+} MonoTryBlockHoleTableJitInfo;
+
+typedef struct
+{
+       guint32 stack_size;
+} MonoArchEHJitInfo;
+
 struct _MonoJitInfo {
        /* NOTE: These first two elements (method and
           next_jit_code_hash) must be in the same order and at the
@@ -126,14 +192,18 @@ struct _MonoJitInfo {
        gboolean    cas_method_deny:1;
        gboolean    cas_method_permitonly:1;
        gboolean    has_generic_jit_info:1;
+       gboolean    has_try_block_holes:1;
+       gboolean    has_arch_eh_info:1;
        gboolean    from_aot:1;
        gboolean    from_llvm:1;
-#ifdef HAVE_SGEN_GC
-       /* FIXME: Embed this after the structure later */
-       gpointer    gc_info;
-#endif
+
+       /* FIXME: Embed this after the structure later*/
+       gpointer    gc_info; /* Currently only used by SGen */
+       
        MonoJitExceptionInfo clauses [MONO_ZERO_LEN_ARRAY];
        /* There is an optional MonoGenericJitInfo after the clauses */
+       /* There is an optional MonoTryBlockHoleTableJitInfo after MonoGenericJitInfo clauses*/
+       /* There is an optional MonoArchEHJitInfo after MonoTryBlockHoleTableJitInfo */
 };
 
 #define MONO_SIZEOF_JIT_INFO (offsetof (struct _MonoJitInfo, clauses))
@@ -167,6 +237,13 @@ typedef struct _MonoThunkFreeList {
 
 typedef struct _MonoJitCodeHash MonoJitCodeHash;
 
+typedef struct _MonoTlsDataRecord MonoTlsDataRecord;
+struct _MonoTlsDataRecord {
+       MonoTlsDataRecord *next;
+       guint32 tls_offset;
+       guint32 size;
+};
+
 struct _MonoDomain {
        /*
         * This lock must never be taken before the loader lock,
@@ -189,6 +266,10 @@ struct _MonoDomain {
        MonoException      *stack_overflow_ex;
        /* typeof (void) */
        MonoObject         *typeof_void;
+       /* Ephemeron Tombstone*/
+       MonoObject         *ephemeron_tombstone;
+       /* new MonoType [0] */
+       MonoArray          *empty_types;
        /* 
         * The fields between FIRST_GC_TRACKED and LAST_GC_TRACKED are roots, but
         * not object references.
@@ -214,7 +295,7 @@ struct _MonoDomain {
        GSList             *domain_assemblies;
        MonoAssembly       *entry_assembly;
        char               *friendly_name;
-       GHashTable         *class_vtable_hash;
+       GPtrArray          *class_vtable_array;
        /* maps remote class key -> MonoRemoteClass */
        GHashTable         *proxy_vtable_hash;
        /* Protected by 'jit_code_hash_lock' */
@@ -233,17 +314,19 @@ struct _MonoDomain {
        MonoMethod         *private_invoke_method;
        /* Used to store offsets of thread and context static fields */
        GHashTable         *special_static_fields;
+       MonoTlsDataRecord  *tlsrec_list;
        /* 
         * This must be a GHashTable, since these objects can't be finalized
         * if the hashtable contains a GC visible reference to them.
         */
        GHashTable         *finalizable_objects_hash;
-#ifndef HAVE_SGEN_GC
+
+       /* These two are boehm only */
        /* Maps MonoObjects to a GSList of WeakTrackResurrection GCHandles pointing to them */
        GHashTable         *track_resurrection_objects_hash;
        /* Maps WeakTrackResurrection GCHandles to the MonoObjects they point to */
        GHashTable         *track_resurrection_handles_hash;
-#endif
+
        /* Protects the three hashes above */
        CRITICAL_SECTION   finalizable_objects_hash_lock;
        /* Used when accessing 'domain_assemblies' */
@@ -254,11 +337,13 @@ struct _MonoDomain {
        GHashTable         *generic_virtual_cases;
        MonoThunkFreeList **thunk_free_lists;
 
+       GHashTable     *generic_virtual_thunks;
+
        /* Information maintained by the JIT engine */
        gpointer runtime_info;
 
        /*thread pool jobs, used to coordinate shutdown.*/
-       int                                     threadpool_jobs;
+       volatile int                    threadpool_jobs;
        HANDLE                          cleanup_semaphore;
        
        /* Contains the compiled runtime invoke wrapper used by finalizers */
@@ -269,6 +354,30 @@ struct _MonoDomain {
 
        /* Contains the compiled method used by async resylt creation to capture thread context*/
        gpointer            capture_context_method;
+
+       /* Assembly bindings, the per-domain part */
+       GSList *assembly_bindings;
+       gboolean assembly_bindings_parsed;
+
+       /* Used by socket-io.c */
+       /* These are domain specific, since the assembly can be unloaded */
+       MonoImage *socket_assembly;
+       MonoClass *sockaddr_class;
+       MonoClassField *sockaddr_data_field;
+
+       /* Used by threadpool.c */
+       MonoImage *system_image;
+       MonoImage *system_net_dll;
+       MonoClass *corlib_asyncresult_class;
+       MonoClass *socket_class;
+       MonoClass *ad_unloaded_ex_class;
+       MonoClass *process_class;
+
+       /* Cache function pointers for architectures  */
+       /* that require wrappers */
+       GHashTable *ftnptrs_hash;
+
+       guint32 execution_context_field_offset;
 };
 
 typedef struct  {
@@ -279,7 +388,7 @@ typedef struct  {
 typedef struct  {
        const char runtime_version [12];
        const char framework_version [4];
-       const AssemblyVersionSet version_sets [2];
+       const AssemblyVersionSet version_sets [3];
 } MonoRuntimeInfo;
 
 #define mono_domain_lock(domain) mono_locks_acquire(&(domain)->lock, DomainLock)
@@ -350,7 +459,7 @@ gpointer
 mono_domain_alloc0 (MonoDomain *domain, guint size) MONO_INTERNAL;
 
 void*
-mono_domain_code_reserve (MonoDomain *domain, int size) MONO_INTERNAL;
+mono_domain_code_reserve (MonoDomain *domain, int size) MONO_LLVM_INTERNAL;
 
 void*
 mono_domain_code_reserve_align (MonoDomain *domain, int size, int alignment) MONO_INTERNAL;
@@ -358,6 +467,12 @@ mono_domain_code_reserve_align (MonoDomain *domain, int size, int alignment) MON
 void
 mono_domain_code_commit (MonoDomain *domain, void *data, int size, int newsize) MONO_INTERNAL;
 
+void *
+nacl_domain_get_code_dest (MonoDomain *domain, void *data) MONO_INTERNAL;
+
+void 
+nacl_domain_code_validate (MonoDomain *domain, guint8 **buf_base, int buf_size, guint8 **code_end) MONO_INTERNAL;
+
 void
 mono_domain_code_foreach (MonoDomain *domain, MonoCodeManagerFunc func, void *user_data) MONO_INTERNAL;
 
@@ -367,6 +482,12 @@ mono_domain_unset (void) MONO_INTERNAL;
 void
 mono_domain_set_internal_with_options (MonoDomain *domain, gboolean migrate_exception) MONO_INTERNAL;
 
+MonoTryBlockHoleTableJitInfo*
+mono_jit_info_get_try_block_hole_table_info (MonoJitInfo *ji) MONO_INTERNAL;
+
+MonoArchEHJitInfo*
+mono_jit_info_get_arch_eh_info (MonoJitInfo *ji) MONO_INTERNAL;
+
 /* 
  * Installs a new function which is used to return a MonoJitInfo for a method inside
  * an AOT module.
@@ -500,4 +621,6 @@ int mono_framework_version (void) MONO_INTERNAL;
 
 void mono_reflection_cleanup_domain (MonoDomain *domain) MONO_INTERNAL;
 
+void mono_assembly_cleanup_domain_bindings (guint32 domain_id) MONO_INTERNAL;;
+
 #endif /* __MONO_METADATA_DOMAIN_INTERNALS_H__ */