[vmkit-commits] [vmkit] r108053 - in /vmkit/trunk: include/mvm/Allocator.h lib/J3/Compiler/ExceptionsCheck.inc lib/J3/Compiler/ExceptionsDwarf.inc lib/J3/Compiler/JavaAOTCompiler.cpp lib/J3/Compiler/JavaJIT.cpp lib/J3/Compiler/JavaJITOpcodes.cpp lib/J3/Compiler/LLVMInfo.cpp lib/J3/Compiler/LLVMMaterializer.cpp lib/J3/VMCore/JavaConstantPool.cpp lib/J3/VMCore/JavaMetaJIT.cpp lib/J3/VMCore/JavaRuntimeJIT.cpp lib/J3/VMCore/JavaTypes.cpp lib/J3/VMCore/JnjvmClassLoader.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Sat Jul 10 13:10:59 PDT 2010


Author: geoffray
Date: Sat Jul 10 15:10:59 2010
New Revision: 108053

URL: http://llvm.org/viewvc/llvm-project?rev=108053&view=rev
Log:
Replace uses of alloca with a ThreadAllocator.


Modified:
    vmkit/trunk/include/mvm/Allocator.h
    vmkit/trunk/lib/J3/Compiler/ExceptionsCheck.inc
    vmkit/trunk/lib/J3/Compiler/ExceptionsDwarf.inc
    vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp
    vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
    vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp
    vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp
    vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp
    vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp
    vmkit/trunk/lib/J3/VMCore/JavaMetaJIT.cpp
    vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp
    vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp
    vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp

Modified: vmkit/trunk/include/mvm/Allocator.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Allocator.h?rev=108053&r1=108052&r2=108053&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/Allocator.h (original)
+++ vmkit/trunk/include/mvm/Allocator.h Sat Jul 10 15:10:59 2010
@@ -45,6 +45,24 @@
 
 };
 
+class ThreadAllocator {
+private:
+  llvm::BumpPtrAllocator Allocator;
+public:
+  void* Allocate(size_t sz) {
+#ifdef USE_GC_BOEHM
+    return GC_MALLOC(sz);
+#else
+    void* res = Allocator.Allocate(sz, sizeof(void*));
+    memset(res, 0, sz);
+    return res;
+#endif
+  }
+
+  void Deallocate(void* obj) {}
+
+};
+
 class PermanentObject {
 public:
   void* operator new(size_t sz, BumpPtrAllocator& allocator,

Modified: vmkit/trunk/lib/J3/Compiler/ExceptionsCheck.inc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/ExceptionsCheck.inc?rev=108053&r1=108052&r2=108053&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/ExceptionsCheck.inc (original)
+++ vmkit/trunk/lib/J3/Compiler/ExceptionsCheck.inc Sat Jul 10 15:10:59 2010
@@ -323,8 +323,10 @@
   sint16 sync = isSynchro(compilingMethod->access) ? 1 : 0;
   nbe += sync;
  
+  mvm::ThreadAllocator allocator;
   // Loop over all handlers in the bytecode to initialize their values.
-  Handler* handlers = (Handler*)alloca(sizeof(Handler) * (nbe - sync));
+  Handler* handlers =
+      (Handler*)allocator.Allocate(sizeof(Handler) * (nbe - sync));
   for (uint16 i = 0; i < nbe - sync; ++i) {
     Handler* ex   = &handlers[i];
     ex->startpc   = reader.readU2();

Modified: vmkit/trunk/lib/J3/Compiler/ExceptionsDwarf.inc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/ExceptionsDwarf.inc?rev=108053&r1=108052&r2=108053&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/ExceptionsDwarf.inc (original)
+++ vmkit/trunk/lib/J3/Compiler/ExceptionsDwarf.inc Sat Jul 10 15:10:59 2010
@@ -225,8 +225,10 @@
     }
   }
   
+  mvm::ThreadAllocator allocator;
   // Loop over all handlers in the bytecode to initialize their values.
-  Handler* handlers = (Handler*)alloca(sizeof(Handler) * (nbe - sync));
+  Handler* handlers = (Handler*)
+      allocator.Allocate(sizeof(Handler) * (nbe - sync));
   for (uint16 i = 0; i < nbe - sync; ++i) {
     Handler* ex   = &handlers[i];
     ex->startpc   = reader.readU2();

Modified: vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp?rev=108053&r1=108052&r2=108053&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaAOTCompiler.cpp Sat Jul 10 15:10:59 2010
@@ -1886,8 +1886,9 @@
                          JnjvmBootstrapLoader* bootstrapLoader,
                          std::vector<Class*>& classes) {
   ZipArchive archive(bytes, bootstrapLoader->allocator);
-    
-  char* realName = (char*)alloca(4096);
+   
+  mvm::ThreadAllocator allocator; 
+  char* realName = (char*)allocator.Allocate(4096);
   for (ZipArchive::table_iterator i = archive.filetable.begin(), 
        e = archive.filetable.end(); i != e; ++i) {
     ZipFile* file = i->second;
@@ -1929,6 +1930,7 @@
   JnjvmBootstrapLoader* bootstrapLoader = vm->bootstrapLoader;
   JavaAOTCompiler* M = (JavaAOTCompiler*)bootstrapLoader->getCompiler();
   JavaJITCompiler* Comp = 0;
+  mvm::ThreadAllocator allocator;
   bootstrapLoader->analyseClasspathEnv(vm->bootstrapLoader->bootClasspathEnv);
   if (!M->clinits->empty()) {
     Comp = JavaJITCompiler::CreateCompiler("JIT");
@@ -1940,22 +1942,22 @@
     bootstrapLoader->upcalls->initialiseClasspath(bootstrapLoader);
   }
   
-    uint32 size = strlen(name);
+  uint32 size = strlen(name);
     
-    if (size > 4 && 
-       (!strcmp(&name[size - 4], ".jar") || !strcmp(&name[size - 4], ".zip"))) {
+  if (size > 4 && 
+      (!strcmp(&name[size - 4], ".jar") || !strcmp(&name[size - 4], ".zip"))) {
   
-      std::vector<Class*> classes;
-      ArrayUInt8* bytes = Reader::openFile(bootstrapLoader, name);
+    std::vector<Class*> classes;
+    ArrayUInt8* bytes = Reader::openFile(bootstrapLoader, name);
       
-      if (!bytes) {
-        fprintf(stderr, "Can't find zip file.\n");
-        goto end;
-      }
+    if (!bytes) {
+      fprintf(stderr, "Can't find zip file.\n");
+      goto end;
+    }
 
-      extractFiles(bytes, M, bootstrapLoader, classes);
-      // Now that we know if we can trust this compiler, add the Java passes.
-      M->addJavaPasses(M->compileRT);
+    extractFiles(bytes, M, bootstrapLoader, classes);
+    // Now that we know if we can trust this compiler, add the Java passes.
+    M->addJavaPasses(M->compileRT);
 
 
       // First resolve everyone so that there can not be unknown references in
@@ -2033,7 +2035,7 @@
       }
 
     } else {
-      char* realName = (char*)alloca(size + 1);
+      char* realName = (char*)allocator.Allocate(size + 1);
       if (size > 6 && !strcmp(&name[size - 6], ".class")) {
         memcpy(realName, name, size - 6);
         realName[size - 6] = 0;

Modified: vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp?rev=108053&r1=108052&r2=108053&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJIT.cpp Sat Jul 10 15:10:59 2010
@@ -1507,7 +1507,8 @@
   nb += 1;
 #endif
   Args.reserve(nb + 2);
-  Value** args = (Value**)alloca(nb*sizeof(Value*));
+  mvm::ThreadAllocator threadAllocator;
+  Value** args = (Value**)threadAllocator.Allocate(nb*sizeof(Value*));
 #if defined(ISOLATE_SHARING)
   args[nb - 1] = isolateLocal;
   sint32 start = nb - 2;

Modified: vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp?rev=108053&r1=108052&r2=108053&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/JavaJITOpcodes.cpp Sat Jul 10 15:10:59 2010
@@ -104,6 +104,7 @@
   bool wide = false;
   uint32 jsrIndex = 0;
   uint32 start = reader.cursor;
+  mvm::ThreadAllocator allocator;
   for(uint32 i = 0; i < codeLength; ++i) {
     reader.cursor = start + i;
     uint8 bytecode = reader.readU1();
@@ -2304,7 +2305,7 @@
         
         UserCommonClass* dcl = 0; 
         Value* valCl = getResolvedCommonClass(index, true, &dcl);
-        Value** args = (Value**)alloca(sizeof(Value*) * (dim + 2));
+        Value** args = (Value**)allocator.Allocate(sizeof(Value*) * (dim + 2));
         args[0] = valCl;
         args[1] = ConstantInt::get(Type::getInt32Ty(*llvmContext), dim);
 

Modified: vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp?rev=108053&r1=108052&r2=108053&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/LLVMInfo.cpp Sat Jul 10 15:10:59 2010
@@ -138,6 +138,7 @@
 
 Function* LLVMMethodInfo::getMethod() {
   if (!methodFunction) {
+    mvm::ThreadAllocator allocator;
     JnjvmClassLoader* JCL = methodDef->classDef->classLoader;
     if (Compiler->emitFunctionName() || EmitDebugInfo) {
       const UTF8* jniConsClName = methodDef->classDef->name;
@@ -147,8 +148,8 @@
       sint32 mnlen = jniConsName->size;
       sint32 mtlen = jniConsType->size;
 
-      char* buf = (char*)alloca(3 + JNI_NAME_PRE_LEN + 1 +
-                                ((mnlen + clen + mtlen) << 3));
+      char* buf = (char*)allocator.Allocate(
+          3 + JNI_NAME_PRE_LEN + 1 + ((mnlen + clen + mtlen) << 3));
       
       bool j3 = false;
       if (isNative(methodDef->access)) {
@@ -327,8 +328,10 @@
   J3Intrinsics& Intrinsics = *Compiler->getIntrinsics();
   Function* res = 0;
   if (Compiler->isStaticCompiling()) {
+    mvm::ThreadAllocator allocator;
     const char* type = virt ? "virtual_buf" : "static_buf";
-    char* buf = (char*)alloca((signature->keyName->size << 1) + 1 + 11);
+    char* buf = (char*)allocator.Allocate(
+        (signature->keyName->size << 1) + 1 + 11);
     signature->nativeName(buf, type);
     res = Function::Create(virt ? getVirtualBufType() : getStaticBufType(),
                            GlobalValue::ExternalLinkage, buf,

Modified: vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp?rev=108053&r1=108052&r2=108053&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp (original)
+++ vmkit/trunk/lib/J3/Compiler/LLVMMaterializer.cpp Sat Jul 10 15:10:59 2010
@@ -82,9 +82,10 @@
   
   Function* F = 0;
   LLVMSignatureInfo* LSI = getSignatureInfo(sign);
+  mvm::ThreadAllocator allocator;
   
   const UTF8* name = cl->name;
-  char* key = (char*)alloca(name->size + 16);
+  char* key = (char*)allocator.Allocate(name->size + 16);
   for (sint32 i = 0; i < name->size; ++i)
     key[i] = name->elements[i];
   sprintf(key + name->size, "%d", index);

Modified: vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp?rev=108053&r1=108052&r2=108053&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaConstantPool.cpp Sat Jul 10 15:10:59 2010
@@ -189,9 +189,10 @@
   }
   
   if (!ctpRes[entry]) {
+    mvm::ThreadAllocator allocator;
     Reader reader(&(classDef->bytes), ctpDef[entry]);
     uint32 len = reader.readU2();
-    uint16* buf = (uint16*)alloca(len * sizeof(uint16));
+    uint16* buf = (uint16*)allocator.Allocate(len * sizeof(uint16));
     uint32 n = 0;
     uint32 i = 0;
   

Modified: vmkit/trunk/lib/J3/VMCore/JavaMetaJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaMetaJIT.cpp?rev=108053&r1=108052&r2=108053&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaMetaJIT.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaMetaJIT.cpp Sat Jul 10 15:10:59 2010
@@ -81,7 +81,8 @@
   llvm_gcroot(obj, 0); \
   verifyNull(obj); \
   Signdef* sign = getSignature(); \
-  jvalue* buf = (jvalue*)alloca(sign->nbArguments * sizeof(jvalue)); \
+  mvm::ThreadAllocator allocator; \
+  jvalue* buf = (jvalue*)allocator.Allocate(sign->nbArguments * sizeof(jvalue)); \
   readArgs(buf, sign, ap, jni); \
   return invoke##TYPE_NAME##VirtualBuf(vm, cl, obj, buf); \
 }\
@@ -90,14 +91,16 @@
   llvm_gcroot(obj, 0); \
   verifyNull(obj); \
   Signdef* sign = getSignature(); \
-  jvalue* buf = (jvalue*)alloca(sign->nbArguments * sizeof(jvalue)); \
+  mvm::ThreadAllocator allocator; \
+  jvalue* buf = (jvalue*)allocator.Allocate(sign->nbArguments * sizeof(jvalue)); \
   readArgs(buf, sign, ap, jni); \
   return invoke##TYPE_NAME##SpecialBuf(vm, cl, obj, buf); \
 }\
 \
 TYPE JavaMethod::invoke##TYPE_NAME##StaticAP(Jnjvm* vm, UserClass* cl, va_list ap) {\
   Signdef* sign = getSignature(); \
-  jvalue* buf = (jvalue*)alloca(sign->nbArguments * sizeof(jvalue)); \
+  mvm::ThreadAllocator allocator; \
+  jvalue* buf = (jvalue*)allocator.Allocate(sign->nbArguments * sizeof(jvalue)); \
   readArgs(buf, sign, ap, jni); \
   return invoke##TYPE_NAME##StaticBuf(vm, cl, buf); \
 }

Modified: vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp?rev=108053&r1=108052&r2=108053&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaRuntimeJIT.cpp Sat Jul 10 15:10:59 2010
@@ -294,7 +294,8 @@
 
   va_list ap;
   va_start(ap, len);
-  sint32* dims = (sint32*)alloca(sizeof(sint32) * len);
+  mvm::ThreadAllocator allocator;
+  sint32* dims = (sint32*)allocator.Allocate(sizeof(sint32) * len);
   for (uint32 i = 0; i < len; ++i){
     dims[i] = va_arg(ap, int);
   }

Modified: vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp?rev=108053&r1=108052&r2=108053&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JavaTypes.cpp Sat Jul 10 15:10:59 2010
@@ -59,7 +59,8 @@
 
 intptr_t Signdef::staticCallBuf() {
   if (!_staticCallBuf) {
-    char* buf = (char*)alloca((keyName->size << 1) + 1 + 11);
+    mvm::ThreadAllocator allocator;
+    char* buf = (char*)allocator.Allocate((keyName->size << 1) + 1 + 11);
     nativeName(buf, "static_buf");
     bool unused = false;
     intptr_t res = initialLoader->loadInLib(buf, unused);
@@ -74,7 +75,8 @@
 
 intptr_t Signdef::virtualCallBuf() {
   if (!_virtualCallBuf) {
-    char* buf = (char*)alloca((keyName->size << 1) + 1 + 11);
+    mvm::ThreadAllocator allocator;
+    char* buf = (char*)allocator.Allocate((keyName->size << 1) + 1 + 11);
     nativeName(buf, "virtual_buf");
     bool unused = false;
     intptr_t res = initialLoader->loadInLib(buf, unused);
@@ -89,7 +91,8 @@
 
 intptr_t Signdef::staticCallAP() {
   if (!_staticCallAP) {
-    char* buf = (char*)alloca((keyName->size << 1) + 1 + 11);
+    mvm::ThreadAllocator allocator;
+    char* buf = (char*)allocator.Allocate((keyName->size << 1) + 1 + 11);
     nativeName(buf, "static_ap");
     bool unused = false;
     intptr_t res = initialLoader->loadInLib(buf, unused);
@@ -104,7 +107,8 @@
 
 intptr_t Signdef::virtualCallAP() {
   if (!_virtualCallAP) {
-    char* buf = (char*)alloca((keyName->size << 1) + 1 + 11);
+    mvm::ThreadAllocator allocator;
+    char* buf = (char*)allocator.Allocate((keyName->size << 1) + 1 + 11);
     nativeName(buf, "virtual_ap");
     bool unused = false;
     intptr_t res = initialLoader->loadInLib(buf, unused);
@@ -119,7 +123,8 @@
 
 intptr_t Signdef::virtualCallStub() {
   if (!_virtualCallAP) {
-    char* buf = (char*)alloca((keyName->size << 1) + 1 + 11);
+    mvm::ThreadAllocator allocator;
+    char* buf = (char*)allocator.Allocate((keyName->size << 1) + 1 + 11);
     nativeName(buf, "virtual_stub");
     bool unused = false;
     intptr_t res = initialLoader->loadInLib(buf, unused);
@@ -134,7 +139,8 @@
 
 intptr_t Signdef::specialCallStub() {
   if (!_specialCallStub) {
-    char* buf = (char*)alloca((keyName->size << 1) + 1 + 11);
+    mvm::ThreadAllocator allocator;
+    char* buf = (char*)allocator.Allocate((keyName->size << 1) + 1 + 11);
     nativeName(buf, "special_stub");
     bool unused = false;
     intptr_t res = initialLoader->loadInLib(buf, unused);
@@ -149,7 +155,8 @@
 
 intptr_t Signdef::staticCallStub() {
   if (!_staticCallStub) {
-    char* buf = (char*)alloca((keyName->size << 1) + 1 + 11);
+    mvm::ThreadAllocator allocator;
+    char* buf = (char*)allocator.Allocate((keyName->size << 1) + 1 + 11);
     nativeName(buf, "static_stub");
     bool unused = false;
     intptr_t res = initialLoader->loadInLib(buf, unused);

Modified: vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp?rev=108053&r1=108052&r2=108053&view=diff
==============================================================================
--- vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp (original)
+++ vmkit/trunk/lib/J3/VMCore/JnjvmClassLoader.cpp Sat Jul 10 15:10:59 2010
@@ -311,8 +311,9 @@
 ArrayUInt8* JnjvmBootstrapLoader::openName(const UTF8* utf8) {
   ArrayUInt8* res = 0;
   llvm_gcroot(res, 0);
+  mvm::ThreadAllocator threadAllocator;
 
-  char* asciiz = (char*)alloca(utf8->size + 1);
+  char* asciiz = (char*)threadAllocator.Allocate(utf8->size + 1);
   for (sint32 i = 0; i < utf8->size; ++i) 
     asciiz[i] = utf8->elements[i];
   asciiz[utf8->size] = 0;
@@ -323,7 +324,7 @@
        e = bootClasspath.end(); i != e; ++i) {
     const char* str = *i;
     unsigned int strLen = strlen(str);
-    char* buf = (char*)alloca(strLen + alen + 7);
+    char* buf = (char*)threadAllocator.Allocate(strLen + alen + 7);
 
     sprintf(buf, "%s%s.class", str, asciiz);
     res = Reader::openFile(this, buf);
@@ -334,7 +335,7 @@
        e = bootArchives.end(); i != e; ++i) {
     
     ZipArchive* archive = *i;
-    char* buf = (char*)alloca(alen + 7);
+    char* buf = (char*)threadAllocator.Allocate(alen + 7);
     sprintf(buf, "%s.class", asciiz);
     res = Reader::openZip(this, archive, buf);
     if (res) return res;
@@ -511,8 +512,10 @@
   if (name->size == 0) {
     return 0;
   } else if (name->elements[0] == I_TAB) {
+    mvm::ThreadAllocator threadAllocator;
     bool prim = false;
-    UTF8* holder = (UTF8*)alloca(sizeof(UTF8) + name->size * sizeof(uint16));
+    UTF8* holder = (UTF8*)threadAllocator.Allocate(
+        sizeof(UTF8) + name->size * sizeof(uint16));
     if (!holder) return 0;
     
     const UTF8* componentName = lookupComponentName(name, holder, prim);
@@ -534,8 +537,10 @@
   const UTF8* name = hashUTF8->lookupAsciiz(asciiz);
   if (!name) name = bootstrapLoader->hashUTF8->lookupAsciiz(asciiz);
   if (!name) {
+    mvm::ThreadAllocator threadAllocator;
     uint32 size = strlen(asciiz);
-    UTF8* temp = (UTF8*)alloca(sizeof(UTF8) + size * sizeof(uint16));
+    UTF8* temp = (UTF8*)threadAllocator.Allocate(
+        sizeof(UTF8) + size * sizeof(uint16));
     temp->size = size;
     if (!temp) return 0;
 
@@ -938,6 +943,7 @@
 void JnjvmBootstrapLoader::analyseClasspathEnv(const char* str) {
   ArrayUInt8* bytes = NULL;
   llvm_gcroot(bytes, 0);
+  mvm::ThreadAllocator threadAllocator;
   if (str != 0) {
     unsigned int len = strlen(str);
     char* buf = new char[len + 1];
@@ -951,7 +957,7 @@
       if (top != 0) {
         memcpy(buf, cur, top);
         buf[top] = 0;
-        char* rp = (char*)alloca(PATH_MAX);
+        char* rp = (char*)threadAllocator.Allocate(PATH_MAX);
         memset(rp, 0, PATH_MAX);
         rp = realpath(buf, rp);
         if (rp && rp[PATH_MAX - 1] == 0 && strlen(rp) != 0) {
@@ -1091,7 +1097,9 @@
 void JnjvmClassLoader::loadLibFromJar(Jnjvm* vm, const char* name,
                                       const char* file) {
 
-  char* soName = (char*)alloca(strlen(name) + strlen(DYLD_EXTENSION));
+  mvm::ThreadAllocator threadAllocator;
+  char* soName = (char*)threadAllocator.Allocate(
+      strlen(name) + strlen(DYLD_EXTENSION));
   const char* ptr = strrchr(name, '/');
   sprintf(soName, "%s%s", ptr ? ptr + 1 : name, DYLD_EXTENSION);
   void* handle = dlopen(soName, RTLD_LAZY | RTLD_LOCAL);
@@ -1107,8 +1115,10 @@
 }
 
 void JnjvmClassLoader::loadLibFromFile(Jnjvm* vm, const char* name) {
+  mvm::ThreadAllocator threadAllocator;
   assert(classes->map.size() == 0);
-  char* soName = (char*)alloca(strlen(name) + strlen(DYLD_EXTENSION));
+  char* soName = (char*)threadAllocator.Allocate(
+      strlen(name) + strlen(DYLD_EXTENSION));
   sprintf(soName, "%s%s", name, DYLD_EXTENSION);
   void* handle = dlopen(soName, RTLD_LAZY | RTLD_LOCAL);
   if (handle) {
@@ -1201,8 +1211,9 @@
   sint32 mnlen = jniConsName->size;
   sint32 mtlen = jniConsType->size;
 
-  char* buf = (char*)alloca(3 + JNI_NAME_PRE_LEN + 1 +
-                            ((mnlen + clen + mtlen) << 3));
+  mvm::ThreadAllocator threadAllocator;
+  char* buf = (char*)threadAllocator.Allocate(
+      3 + JNI_NAME_PRE_LEN + 1 + ((mnlen + clen + mtlen) << 3));
   intptr_t res = meth->classDef->classLoader->nativeLookup(meth, j3, buf);
   assert(res && "Could not find required native method");
   return res;





More information about the vmkit-commits mailing list