Make the compiler threadsafe
The compiler inherited a simple memory management scheme that
involved malloc'ng a clump of memory, allocating out of that
clump for each unit of compilation, and then resetting after
the compilation was complete. Simple & fast, but built with the
expectation of a single compiler worker thread.
This change moves the memory allocation arena into the
CompilationUnit structure, and makes it private for each method
compilation. Unlike the old scheme, allocated memory is returned
to the system following completion (whereas before it was reused
for the next compilation).
As of this CL, each compilation is completely independent.
The changes involved were mostly mechanical to pass around the
cUnit pointer to anything which might need to allocate, but the
accretion of crud has moved me much closer to the point that
all of this stuff gets ripped out and replaced.
Change-Id: I19dda0a7fb5aa228f6baee7ae5293fdd174c8337
diff --git a/src/compiler/CompilerUtility.h b/src/compiler/CompilerUtility.h
index ba449a4..a6ddd1e 100644
--- a/src/compiler/CompilerUtility.h
+++ b/src/compiler/CompilerUtility.h
@@ -22,10 +22,10 @@
namespace art {
/* Each arena page has some overhead, so take a few bytes off */
-#define ARENA_DEFAULT_SIZE ((256 * 1024) - 256)
+#define ARENA_DEFAULT_SIZE ((2 * 1024 * 1024) - 256)
/* Allocate the initial memory block for arena-based allocation */
-bool oatHeapInit(void);
+bool oatHeapInit(CompilationUnit* cUnit);
/* Collect memory usage statstics */
//#define WITH_MEMSTATS
@@ -37,9 +37,10 @@
char ptr[0];
} ArenaMemBlock;
-void* oatNew(size_t size, bool zero, oatAllocKind kind = kAllocMisc);
+void* oatNew(CompilationUnit* cUnit, size_t size, bool zero,
+ oatAllocKind kind = kAllocMisc);
-void oatArenaReset(void);
+void oatArenaReset(CompilationUnit *cUnit);
typedef struct GrowableList {
size_t numAllocated;
@@ -87,21 +88,23 @@
struct BasicBlock;
struct CompilationUnit;
-void oatInitGrowableList(GrowableList* gList, size_t initLength,
- oatListKind kind = kListMisc);
-void oatInsertGrowableList(GrowableList* gList, intptr_t elem);
+void oatInitGrowableList(CompilationUnit* cUnit,GrowableList* gList,
+ size_t initLength, oatListKind kind = kListMisc);
+void oatInsertGrowableList(CompilationUnit* cUnit, GrowableList* gList,
+ intptr_t elem);
void oatDeleteGrowableList(GrowableList* gList, intptr_t elem);
void oatGrowableListIteratorInit(GrowableList* gList,
GrowableListIterator* iterator);
intptr_t oatGrowableListIteratorNext(GrowableListIterator* iterator);
intptr_t oatGrowableListGetElement(const GrowableList* gList, size_t idx);
-ArenaBitVector* oatAllocBitVector(unsigned int startBits, bool expandable,
+ArenaBitVector* oatAllocBitVector(CompilationUnit* cUnit,
+ unsigned int startBits, bool expandable,
oatBitMapKind = kBitMapMisc);
void oatBitVectorIteratorInit(ArenaBitVector* pBits,
ArenaBitVectorIterator* iterator);
int oatBitVectorIteratorNext(ArenaBitVectorIterator* iterator);
-bool oatSetBit(ArenaBitVector* pBits, unsigned int num);
+bool oatSetBit(CompilationUnit *cUnit, ArenaBitVector* pBits, unsigned int num);
bool oatClearBit(ArenaBitVector* pBits, unsigned int num);
void oatMarkAllBits(ArenaBitVector* pBits, bool set);
void oatDebugBitVector(char* msg, const ArenaBitVector* bv, int length);