#include <nacl/nacl_dyncode.h>
#include <mono/mini/mini.h>
#endif
+#include <mono/utils/mono-mutex.h>
+
static uintptr_t code_memory_used = 0;
static size_t dynamic_code_alloc_count;
#define VALLOC_FREELIST_SIZE 16
-static CRITICAL_SECTION valloc_mutex;
+static mono_mutex_t valloc_mutex;
static GHashTable *valloc_freelists;
static void*
GSList *freelist;
if (!valloc_freelists) {
- InitializeCriticalSection (&valloc_mutex);
+ mono_mutex_init_recursive (&valloc_mutex);
valloc_freelists = g_hash_table_new (NULL, NULL);
}
/*
* Keep a small freelist of memory blocks to decrease pressure on the kernel memory subsystem to avoid #3321.
*/
- EnterCriticalSection (&valloc_mutex);
+ mono_mutex_lock (&valloc_mutex);
freelist = g_hash_table_lookup (valloc_freelists, GUINT_TO_POINTER (size));
if (freelist) {
ptr = freelist->data;
if (!ptr && preferred)
ptr = mono_valloc (NULL, size, MONO_PROT_RWX | ARCH_MAP_FLAGS);
}
- LeaveCriticalSection (&valloc_mutex);
+ mono_mutex_unlock (&valloc_mutex);
return ptr;
}
{
GSList *freelist;
- EnterCriticalSection (&valloc_mutex);
+ mono_mutex_lock (&valloc_mutex);
freelist = g_hash_table_lookup (valloc_freelists, GUINT_TO_POINTER (size));
if (!freelist || g_slist_length (freelist) < VALLOC_FREELIST_SIZE) {
freelist = g_slist_prepend (freelist, ptr);
} else {
mono_vfree (ptr, size);
}
- LeaveCriticalSection (&valloc_mutex);
+ mono_mutex_unlock (&valloc_mutex);
}
static void
void
mono_code_manager_init (void)
{
- mono_counters_register ("Dynamic code allocs", MONO_COUNTER_JIT | MONO_COUNTER_WORD, &dynamic_code_alloc_count);
- mono_counters_register ("Dynamic code bytes", MONO_COUNTER_JIT | MONO_COUNTER_WORD, &dynamic_code_bytes_count);
- mono_counters_register ("Dynamic code frees", MONO_COUNTER_JIT | MONO_COUNTER_WORD, &dynamic_code_frees_count);
+ mono_counters_register ("Dynamic code allocs", MONO_COUNTER_JIT | MONO_COUNTER_ULONG, &dynamic_code_alloc_count);
+ mono_counters_register ("Dynamic code bytes", MONO_COUNTER_JIT | MONO_COUNTER_ULONG, &dynamic_code_bytes_count);
+ mono_counters_register ("Dynamic code frees", MONO_COUNTER_JIT | MONO_COUNTER_ULONG, &dynamic_code_frees_count);
}
void
#if defined(__arm__)
#define BIND_ROOM 8
#endif
+#if defined(TARGET_ARM64)
+#define BIND_ROOM 8
+#endif
static CodeChunk*
new_codechunk (CodeChunk *last, int dynamic, int size)
return NULL;
} else {
/* Try to allocate code chunks next to each other to help the VM */
+ ptr = NULL;
if (last)
ptr = codechunk_valloc ((guint8*)last->data + last->size, chunk_size);
- else
+ if (!ptr)
ptr = codechunk_valloc (NULL, chunk_size);
if (!ptr)
return NULL;