+#ifndef MALLOC_ALLOCATION
+#ifdef TRACE_ALLOCATIONS
+#include <execinfo.h>
+#include "metadata/appdomain.h"
+#include "metadata/metadata-internals.h"
+
+static CRITICAL_SECTION mempool_tracing_lock;
+#define BACKTRACE_DEPTH 7
+static void
+mono_backtrace (int size)
+{
+ void *array[BACKTRACE_DEPTH];
+ char **names;
+ int i, symbols;
+ static gboolean inited;
+
+ if (!inited) {
+ InitializeCriticalSection (&mempool_tracing_lock);
+ inited = TRUE;
+ }
+
+ EnterCriticalSection (&mempool_tracing_lock);
+ g_print ("Allocating %d bytes\n", size);
+ symbols = backtrace (array, BACKTRACE_DEPTH);
+ names = backtrace_symbols (array, symbols);
+ for (i = 1; i < symbols; ++i) {
+ g_print ("\t%s\n", names [i]);
+ }
+ free (names);
+ LeaveCriticalSection (&mempool_tracing_lock);
+}
+
+#endif
+
+static int
+get_next_size (MonoMemPool *pool, int size)
+{
+ int target = pool->next? pool->next->size: pool->size;
+ size += sizeof (MonoMemPool);
+ /* increase the size */
+ target += target / 2;
+ while (target < size) {
+ target += target / 2;
+ }
+ if (target > MONO_MEMPOOL_PAGESIZE && size <= MONO_MEMPOOL_PAGESIZE)
+ target = MONO_MEMPOOL_PAGESIZE;
+ return target;
+}
+#endif
+