[jit] Add support for computing the size of the branch binding area by backends and...
authorZoltan Varga <vargaz@gmail.com>
Sat, 11 Apr 2015 01:52:39 +0000 (21:52 -0400)
committerZoltan Varga <vargaz@gmail.com>
Sat, 11 Apr 2015 01:52:39 +0000 (21:52 -0400)
mono/mini/mini.c
mono/mini/mini.h
mono/utils/mono-codeman.c
mono/utils/mono-codeman.h

index 82c756e0985a9a2b73ca60c6a3414dd8c3f439aa..1a0ac0139df9065e862b624ea19dce87e3e3db87 100755 (executable)
@@ -2464,7 +2464,7 @@ mono_codegen (MonoCompile *cfg)
 #endif
                /* Allocate the code into a separate memory pool so it can be freed */
                cfg->dynamic_info = g_new0 (MonoJitDynamicMethodInfo, 1);
-               cfg->dynamic_info->code_mp = mono_code_manager_new_dynamic ();
+               cfg->dynamic_info->code_mp = mono_code_manager_new_dynamic (cfg->thunk_area);
                mono_domain_lock (cfg->domain);
                mono_dynamic_code_hash_insert (cfg->domain, cfg->method, cfg->dynamic_info);
                mono_domain_unlock (cfg->domain);
index 148158b3f47f607744b030bffbf2223552fb8943..4c2c9714107f9fa836d204f3d16317d3019517c0 100644 (file)
@@ -1541,6 +1541,8 @@ typedef struct {
        GHashTable       *token_info_hash;
        MonoCompileArch  arch;
        guint32          inline_depth;
+       /* Size of memory reserved for thunks */
+       int              thunk_area;
        guint32          exception_type;        /* MONO_EXCEPTION_* */
        guint32          exception_data;
        char*            exception_message;
index 2237445838e9759a098575f45cbfaf34c6d16e44..08b8226f61b44050928b1813e86ed6d3ddb59852 100644 (file)
@@ -96,6 +96,7 @@ struct _CodeChunck {
 struct _MonoCodeManager {
        int dynamic;
        int read_only;
+       int bind_size;
        CodeChunk *current;
        CodeChunk *full;
        CodeChunk *last;
@@ -365,14 +366,17 @@ mono_code_manager_new (void)
  * Creates a new code manager suitable for holding native code that can be
  * used for single or small methods that need to be deallocated independently
  * of other native code.
+ * BIND_SIZE is the amount of memory reserved for storing thunks. If its 0,
+ * the default size is used.
  *
  * Returns: the new code manager
  */
 MonoCodeManager* 
-mono_code_manager_new_dynamic (void)
+mono_code_manager_new_dynamic (int bind_size)
 {
        MonoCodeManager *cman = mono_code_manager_new ();
        cman->dynamic = 1;
+       cman->bind_size = bind_size;
        return cman;
 }
 
@@ -496,7 +500,7 @@ mono_code_manager_foreach (MonoCodeManager *cman, MonoCodeManagerFunc func, void
 #endif
 
 static CodeChunk*
-new_codechunk (CodeChunk *last, int dynamic, int size)
+new_codechunk (CodeChunk *last, int dynamic, int size, int bind_size)
 {
        int minsize, flags = CODE_FLAG_MMAP;
        int chunk_size, bsize = 0;
@@ -529,11 +533,15 @@ new_codechunk (CodeChunk *last, int dynamic, int size)
                }
        }
 #ifdef BIND_ROOM
-       if (dynamic)
-               /* Reserve more space since there are no other chunks we might use if this one gets full */
-               bsize = (chunk_size * 2) / BIND_ROOM;
-       else
-               bsize = chunk_size / BIND_ROOM;
+       if (bind_size) {
+               bsize = bind_size;
+       } else {
+               if (dynamic)
+                       /* Reserve more space since there are no other chunks we might use if this one gets full */
+                       bsize = (chunk_size * 2) / BIND_ROOM;
+               else
+                       bsize = chunk_size / BIND_ROOM;
+       }
        if (bsize < MIN_BSIZE)
                bsize = MIN_BSIZE;
        bsize += MIN_ALIGN -1;
@@ -622,7 +630,7 @@ mono_code_manager_reserve_align (MonoCodeManager *cman, int size, int alignment)
        }
 
        if (!cman->current) {
-               cman->current = new_codechunk (cman->last, cman->dynamic, size);
+               cman->current = new_codechunk (cman->last, cman->dynamic, size, cman->bind_size);
                if (!cman->current)
                        return NULL;
                cman->last = cman->current;
@@ -655,7 +663,7 @@ mono_code_manager_reserve_align (MonoCodeManager *cman, int size, int alignment)
                cman->full = chunk;
                break;
        }
-       chunk = new_codechunk (cman->last, cman->dynamic, size);
+       chunk = new_codechunk (cman->last, cman->dynamic, size, cman->bind_size);
        if (!chunk)
                return NULL;
        chunk->next = cman->current;
index 17d53b3b0328ab81161646b1e4fade010c367af2..fb3e5ea680370c849903bfd573ab461e56d93ea0 100644 (file)
@@ -6,7 +6,7 @@
 typedef struct _MonoCodeManager MonoCodeManager;
 
 MONO_API MonoCodeManager* mono_code_manager_new     (void);
-MONO_API MonoCodeManager* mono_code_manager_new_dynamic (void);
+MONO_API MonoCodeManager* mono_code_manager_new_dynamic (int bind_size);
 MONO_API void             mono_code_manager_destroy (MonoCodeManager *cman);
 MONO_API void             mono_code_manager_invalidate (MonoCodeManager *cman);
 MONO_API void             mono_code_manager_set_read_only (MonoCodeManager *cman);