2010-06-17 Geoff Norton <gnorton@novell.com>
[mono.git] / mono / metadata / domain-internals.h
index 24c880356da3157b8c4ce2c690f907736fc17ff9..fdcfdf420eb413c1211cbd7e8dd7cd162773d396 100644 (file)
@@ -5,12 +5,14 @@
 #define __MONO_METADATA_DOMAIN_INTERNALS_H__
 
 #include <mono/metadata/appdomain.h>
+#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/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;
@@ -43,10 +45,11 @@ typedef struct {
        MonoBoolean disallow_code_downloads;
        MonoObject *activation_arguments; /* it is System.Object in 1.x, ActivationArguments in 2.0 */
        MonoObject *domain_initializer;
-       MonoArray *domain_initializer_args;
        MonoObject *application_trust; /* it is System.Object in 1.x, ApplicationTrust in 2.0 */
+       MonoArray *domain_initializer_args;
        MonoBoolean disallow_appbase_probe;
        MonoArray *configuration_bytes;
+       MonoArray *serialized_non_primitives;
 } MonoAppDomainSetup;
 
 typedef struct _MonoJitInfoTable MonoJitInfoTable;
@@ -69,6 +72,8 @@ struct _MonoJitInfoTable
        MonoJitInfoTableChunk  *chunks [MONO_ZERO_LEN_ARRAY];
 };
 
+#define MONO_SIZEOF_JIT_INFO_TABLE (sizeof (struct _MonoJitInfoTable) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
+
 typedef GArray MonoAotModuleInfoTable;
 
 typedef struct {
@@ -80,6 +85,7 @@ typedef struct {
        union {
                MonoClass *catch_class;
                gpointer filter;
+               gpointer handler_end;
        } data;
 } MonoJitExceptionInfo;
 
@@ -100,6 +106,42 @@ typedef struct
        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;
+
 struct _MonoJitInfo {
        /* NOTE: These first two elements (method and
           next_jit_code_hash) must be in the same order and at the
@@ -122,15 +164,20 @@ 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    from_aot:1;
+       gboolean    from_llvm:1;
 #ifdef HAVE_SGEN_GC
        /* FIXME: Embed this after the structure later */
        gpointer    gc_info;
 #endif
        MonoJitExceptionInfo clauses [MONO_ZERO_LEN_ARRAY];
        /* There is an optional MonoGenericJitInfo after the clauses */
+       /* There is an optional MonoTryBlockHoleTableJitInfo after MonoGenericJitInfo clauses*/
 };
 
+#define MONO_SIZEOF_JIT_INFO (offsetof (struct _MonoJitInfo, clauses))
+
 struct _MonoAppContext {
        MonoObject obj;
        gint32 domain_id;
@@ -182,6 +229,8 @@ struct _MonoDomain {
        MonoException      *stack_overflow_ex;
        /* typeof (void) */
        MonoObject         *typeof_void;
+       /* Ephemeron Tombstone*/
+       MonoObject         *ephemeron_tombstone;
        /* 
         * The fields between FIRST_GC_TRACKED and LAST_GC_TRACKED are roots, but
         * not object references.
@@ -207,7 +256,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' */
@@ -251,7 +300,7 @@ struct _MonoDomain {
        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 */
@@ -262,6 +311,10 @@ 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;
 };
 
 typedef struct  {
@@ -354,9 +407,15 @@ mono_domain_code_commit (MonoDomain *domain, void *data, int size, int newsize)
 void
 mono_domain_code_foreach (MonoDomain *domain, MonoCodeManagerFunc func, void *user_data) MONO_INTERNAL;
 
+void
+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;
+
 /* 
  * Installs a new function which is used to return a MonoJitInfo for a method inside
  * an AOT module.
@@ -469,9 +528,6 @@ mono_runtime_get_no_exec (void) MONO_INTERNAL;
 gboolean
 mono_assembly_name_parse (const char *name, MonoAssemblyName *aname) MONO_INTERNAL;
 
-void
-mono_assembly_name_free (MonoAssemblyName *aname) MONO_INTERNAL;
-
 MonoImage *mono_assembly_open_from_bundle (const char *filename,
                                           MonoImageOpenStatus *status,
                                           gboolean refonly) MONO_INTERNAL;