[vmkit-commits] [vmkit] r57374 - in /vmkit/trunk: include/mvm/Allocator.h lib/JnJVM/Classpath/ClasspathVMObject.cpp lib/JnJVM/VMCore/JavaAllocator.h lib/JnJVM/VMCore/JavaArray.cpp lib/JnJVM/VMCore/JavaArray.h lib/JnJVM/VMCore/JavaClass.cpp lib/JnJVM/VMCore/JavaClass.h lib/JnJVM/VMCore/Jnjvm.cpp lib/JnJVM/VMCore/Jnjvm.h lib/JnJVM/VMCore/JnjvmClassLoader.cpp lib/JnJVM/VMCore/JnjvmClassLoader.h lib/JnJVM/VMCore/LockedMap.cpp lib/JnJVM/VMCore/LockedMap.h lib/JnJVM/VMCore/Zip.cpp lib/JnJVM/VMCore/Zip.h

Nicolas Geoffray nicolas.geoffray at lip6.fr
Sat Oct 11 05:54:40 PDT 2008


Author: geoffray
Date: Sat Oct 11 07:54:38 2008
New Revision: 57374

URL: http://llvm.org/viewvc/llvm-project?rev=57374&view=rev
Log:
Move the Allocator to mvm, it is not jnjvm-specific.


Added:
    vmkit/trunk/include/mvm/Allocator.h
Removed:
    vmkit/trunk/lib/JnJVM/VMCore/JavaAllocator.h
Modified:
    vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMObject.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h
    vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
    vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h
    vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h
    vmkit/trunk/lib/JnJVM/VMCore/LockedMap.cpp
    vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h
    vmkit/trunk/lib/JnJVM/VMCore/Zip.cpp
    vmkit/trunk/lib/JnJVM/VMCore/Zip.h

Added: vmkit/trunk/include/mvm/Allocator.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Allocator.h?rev=57374&view=auto

==============================================================================
--- vmkit/trunk/include/mvm/Allocator.h (added)
+++ vmkit/trunk/include/mvm/Allocator.h Sat Oct 11 07:54:38 2008
@@ -0,0 +1,66 @@
+//===----------- Allocator.h - A memory allocator  ------------------------===//
+//
+//                        The VMKit project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MVM_ALLOCATOR_H
+#define MVM_ALLOCATOR_H
+
+#include <cstdlib>
+
+#include "MvmGC.h"
+
+#ifdef MULTIPLE_GC
+#define allocator_new(alloc, cl) collector_new(cl, alloc.GC)
+#else
+#define allocator_new(alloc, cl) gc_new(cl)
+#endif
+
+namespace mvm {
+
+
+class Allocator {
+private:
+#ifdef MULTIPLE_GC
+  Collector* GC;
+#endif
+
+public:
+  
+#ifndef MULTIPLE_GC
+  void* allocateManagedObject(unsigned int sz, VirtualTable* VT) {
+    return gc::operator new(sz, VT);
+  }
+#else
+  void* allocateManagedObject(unsigned int sz, VirtualTable* VT) {
+    return gc::operator new(sz, VT, GC);
+  }
+#endif
+  
+  void* allocatePermanentMemory(unsigned int sz) {
+    return malloc(sz); 
+  }
+  
+  void freePermanentMemory(void* obj) {
+    return free(obj); 
+  }
+};
+
+class PermanentObject {
+public:
+  void* operator new(size_t sz, Allocator* allocator) {
+    return allocator->allocatePermanentMemory(sz);
+  }
+
+  void operator delete(void* obj, Allocator* allocator) {
+    allocator->freePermanentMemory(obj);
+  }
+};
+
+} // end namespace mvm
+
+#endif // MVM_ALLOCATOR_H

Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMObject.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMObject.cpp?rev=57374&r1=57373&r2=57374&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMObject.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMObject.cpp Sat Oct 11 07:54:38 2008
@@ -41,7 +41,7 @@
     size = cl->getVirtualSize();
   }
   JavaObject* res = (JavaObject*)
-    vm->allocator.allocateObject(size, src->getVirtualTable());
+    vm->allocator.allocateManagedObject(size, src->getVirtualTable());
   memcpy(res, src, size);
   res->lock = 0;
   return (jobject)res;

Removed: vmkit/trunk/lib/JnJVM/VMCore/JavaAllocator.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaAllocator.h?rev=57373&view=auto

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaAllocator.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaAllocator.h (removed)
@@ -1,45 +0,0 @@
-//===------- JavaAllocator.h - A memory allocator for Jnjvm ---------------===//
-//
-//                              JnJVM
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef JNJVM_JAVA_ALLOCATOR_H
-#define JNJVM_JAVA_ALLOCATOR_H
-
-#include "MvmGC.h"
-
-#ifdef MULTIPLE_GC
-#define allocator_new(alloc, cl) collector_new(cl, alloc.GC)
-#else
-#define allocator_new(alloc, cl) gc_new(cl)
-#endif
-
-namespace jnjvm {
-
-class JavaAllocator {
-
-#ifdef MULTIPLE_GC
-  Collector* GC;
-#endif
-
-public:
-  
-#ifndef MULTIPLE_GC
-  void* allocateObject(unsigned int sz, VirtualTable* VT) {
-    return gc::operator new(sz, VT);
-  }
-#else
-  void* allocateObject(unsigned int sz, VirtualTable* VT) {
-    return gc::operator new(sz, VT, GC);
-  }
-#endif
-
-};
-
-} // end namespace jnjvm
-
-#endif // JNJVM_JAVA_ALLOCATOR_H

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp?rev=57374&r1=57373&r2=57374&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaArray.cpp Sat Oct 11 07:54:38 2008
@@ -34,10 +34,6 @@
 const unsigned int JavaArray::T_INT = 10;
 const unsigned int JavaArray::T_LONG = 11;
 
-// This will force linking runtime methods
-extern "C" void negativeArraySizeException(sint32 val);
-extern "C" void outOfMemoryError(sint32 val);
-
 void UTF8::print(mvm::PrintBuffer* buf) const {
   for (int i = 0; i < size; i++)
     buf->writeChar((char)elements[i]);
@@ -55,6 +51,8 @@
   return map->lookupOrCreateReader(java, len);
 }
 
+// We also define a checked java to internal function to disallow
+// users to load classes with '/'.
 const UTF8* UTF8::checkedJavaToInternal(UTF8Map* map, unsigned int start,
                                         unsigned int len) const {
   uint16* java = (uint16*) alloca(len * sizeof(uint16));
@@ -100,6 +98,7 @@
   buf->setAt(size, 0);
   return buf->cString();
 #else
+  // To bypass GC-allocation, use malloc here. Only when debugging.
   char* buf = (char*)malloc(size + 1);
   for (sint32 i = 0; i < size; ++i) {
     buf[i] =  elements[i];
@@ -110,23 +109,18 @@
 }
 
 /// Currently, this uses malloc/free. This should use a custom memory pool.
-void* UTF8::operator new(size_t sz, sint32 size) {
-  return malloc(sz + size * sizeof(uint16));
-}
-
-void UTF8::operator delete(void* obj) {
-  free(obj);
+void* UTF8::operator new(size_t sz, mvm::Allocator* allocator, sint32 size) {
+  return allocator->allocatePermanentMemory(sz + size * sizeof(uint16));
 }
 
-
 const UTF8* UTF8::acons(sint32 n, UserClassArray* cl,
-                        JavaAllocator* allocator) {
-  if (n < 0)
-    negativeArraySizeException(n);
-  else if (n > JavaArray::MaxArraySize)
-    outOfMemoryError(n);                                                  
-  UTF8* res = new (n) UTF8();
+                        mvm::Allocator* allocator) {
+  assert(n >= 0 && "Creating an UTF8 with a size < 0");
+  assert(n <= JavaArray::MaxArraySize && 
+         "Creating an UTF8 with a size too big");
+
+  UTF8* res = new (allocator, n) UTF8();
   res->initialise(cl);
-  res->size = n;                                                          
-  return (const UTF8*)res;                                                         
+  res->size = n; 
+  return (const UTF8*)res;
 }

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h?rev=57374&r1=57373&r2=57374&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaArray.h Sat Oct 11 07:54:38 2008
@@ -14,6 +14,7 @@
 #ifndef JNJVM_JAVA_ARRAY_H
 #define JNJVM_JAVA_ARRAY_H
 
+#include "mvm/Allocator.h"
 #include "mvm/PrintBuffer.h"
 
 #include "types.h"
@@ -24,7 +25,6 @@
 
 class ClassArray;
 class CommonClass;
-class JavaAllocator;
 class JavaObject;
 class Jnjvm;
 
@@ -117,7 +117,7 @@
   /// acons - Allocates an UTF8 in permanent memory. The class argument must be
   /// JavaArray::ofChar.
   static const UTF8* acons(sint32 n, UserClassArray* cl,
-                           JavaAllocator* allocator);
+                           mvm::Allocator* allocator);
 
   /// internalToJava - Creates a copy of the UTF8 at its given offset and size
   /// woth all its '.' replaced by '/'. The JVM bytecode reference classes in
@@ -165,11 +165,8 @@
 
   /// operator new - Redefines the new operator of this class to allocate
   /// its objects in permanent memory, not with the garbage collector.
-  void* operator new(size_t sz, sint32 size);
+  void* operator new(size_t sz, mvm::Allocator* allocator, sint32 size);
 
-  /// operator delete - Redefines the delete operator to remove the object
-  /// from permanent memory.
-  void operator delete(void* obj);
 };
 
 } // end namespace jnjvm

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp?rev=57374&r1=57373&r2=57374&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Sat Oct 11 07:54:38 2008
@@ -340,13 +340,13 @@
   return doNew(n, vm->allocator);
 }
 
-JavaArray* UserClassArray::doNew(sint32 n, JavaAllocator& allocator) {
+JavaArray* UserClassArray::doNew(sint32 n, mvm::Allocator& allocator) {
   UserCommonClass* cl = baseClass();
   assert(cl && virtualVT && "array class not resolved");
 
   uint32 primSize = cl->isPrimitive() ? cl->virtualSize : sizeof(JavaObject*);
   uint32 size = sizeof(JavaObject) + sizeof(sint32) + n * primSize;
-  JavaArray* res = (JavaArray*)allocator.allocateObject(size, virtualVT);
+  JavaArray* res = (JavaArray*)allocator.allocateManagedObject(size, virtualVT);
   res->initialise(this);
   res->size = n;
   return res;
@@ -486,8 +486,9 @@
 JavaObject* UserClass::doNew(Jnjvm* vm) {
   assert(this && "No class when allocating.");
   assert(this->isReady() && "Uninitialized class when allocating.");
-  JavaObject* res = (JavaObject*)vm->allocator.allocateObject(getVirtualSize(),
-                                                              getVirtualVT());
+  JavaObject* res = 
+    (JavaObject*)vm->allocator.allocateManagedObject(getVirtualSize(),
+                                                     getVirtualVT());
   res->classOf = this;
   return res;
 }

Modified: vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h?rev=57374&r1=57373&r2=57374&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Sat Oct 11 07:54:38 2008
@@ -15,6 +15,7 @@
 
 #include "types.h"
 
+#include "mvm/Allocator.h"
 #include "mvm/JIT.h"
 #include "mvm/Method.h"
 #include "mvm/Object.h"
@@ -23,7 +24,6 @@
 #include "mvm/Threads/Locks.h"
 
 #include "JavaAccess.h"
-#include "JavaAllocator.h"
 #include "JnjvmClassLoader.h"
 
 namespace jnjvm {
@@ -708,9 +708,9 @@
   /// Reader is a friend because it allocates arrays without a vm.
   friend class Reader;
 private:
-  /// doNew - Allocate a new array with the given loader.
+  /// doNew - Allocate a new array with the given allocator.
   ///
-  JavaArray* doNew(sint32 n, JavaAllocator& allocator);
+  JavaArray* doNew(sint32 n, mvm::Allocator& allocator);
 
 public:
   

Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp?rev=57374&r1=57373&r2=57374&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Sat Oct 11 07:54:38 2008
@@ -121,8 +121,8 @@
       PRINT_DEBUG(JNJVM_LOAD, 0, COLOR_NORMAL, "%s\n", printString());
       
       JavaObject* val = 
-        (JavaObject*)vm->allocator.allocateObject(cl->getStaticSize(),
-                                                  cl->getStaticVT());
+        (JavaObject*)vm->allocator.allocateManagedObject(cl->getStaticSize(),
+                                                         cl->getStaticVT());
       val->initialise(cl);
       CommonClass::field_map* map = cl->getStaticFields();
       for (CommonClass::field_iterator i = map->begin(), e = map->end(); i!= e;
@@ -446,7 +446,7 @@
   ArrayUInt8* bytes = Reader::openFile(vm->bootstrapLoader,
                                        jarFile);
 
-  ZipArchive archive(bytes);
+  ZipArchive archive(bytes, &vm->allocator);
   if (archive.getOfscd() != -1) {
     ZipFile* file = archive.getFile(PATH_MANIFEST);
     if (file) {

Modified: vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h?rev=57374&r1=57373&r2=57374&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Sat Oct 11 07:54:38 2008
@@ -14,13 +14,13 @@
 
 #include "types.h"
 
+#include "mvm/Allocator.h"
 #include "mvm/Object.h"
 #include "mvm/PrintBuffer.h"
 #include "mvm/VirtualMachine.h"
 #include "mvm/Threads/Cond.h"
 #include "mvm/Threads/Locks.h"
 
-#include "JavaAllocator.h"
 #include "JavaTypes.h"
 #include "JnjvmConfig.h"
 
@@ -231,7 +231,7 @@
 
   /// allocator - Memory allocator of this JVM.
   ///
-  JavaAllocator allocator;
+  mvm::Allocator allocator;
   
   /// jniEnv - The JNI environment of this JVM.
   ///

Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp?rev=57374&r1=57373&r2=57374&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Sat Oct 11 07:54:38 2008
@@ -13,7 +13,8 @@
 
 #include "debug.h"
 
-#include "JavaAllocator.h"
+#include "mvm/Allocator.h"
+
 #include "JavaClass.h"
 #include "JavaConstantPool.h"
 #include "JavaThread.h"
@@ -44,7 +45,7 @@
   JCL->TheModule = new JnjvmModule("Bootstrap JnJVM");
   JCL->TheModuleProvider = new JnjvmModuleProvider(JCL->TheModule);
   
-  JCL->allocator = new JavaAllocator();
+  JCL->allocator = new mvm::Allocator();
   
   JCL->hashUTF8 = new UTF8Map(JCL->allocator, 0);
   JCL->classes = new ClassMap();
@@ -74,7 +75,7 @@
   TheModuleProvider = new JnjvmModuleProvider(TheModule);
   bootstrapLoader = JCL.bootstrapLoader;
   
-  allocator = &(isolate->allocator);
+  allocator = new mvm::Allocator();
 
   hashUTF8 = new UTF8Map(allocator, bootstrapLoader->upcalls->ArrayOfChar);
   classes = new ClassMap();
@@ -426,7 +427,7 @@
             ArrayUInt8* bytes =
               Reader::openFile(this, rp);
             if (bytes) {
-              ZipArchive *archive = new ZipArchive(bytes);
+              ZipArchive *archive = new(allocator) ZipArchive(bytes, allocator);
               if (archive) {
                 bootArchives.push_back(archive);
               }

Modified: vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h?rev=57374&r1=57373&r2=57374&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Sat Oct 11 07:54:38 2008
@@ -15,6 +15,7 @@
 
 #include "types.h"
 
+#include "mvm/Allocator.h"
 #include "mvm/Object.h"
 #include "mvm/PrintBuffer.h"
 
@@ -29,7 +30,6 @@
 class ClassMap;
 class Classpath;
 class UserCommonClass;
-class JavaAllocator;
 class JavaObject;
 class JavaString;
 class Jnjvm;
@@ -96,7 +96,7 @@
   /// allocator - Reference to the memory allocator, which will allocate UTF8s,
   /// signatures and types.
   ///
-  JavaAllocator* allocator;
+  mvm::Allocator* allocator;
    
   
   /// hashUTF8 - Tables of UTF8s defined by this class loader. Shared

Modified: vmkit/trunk/lib/JnJVM/VMCore/LockedMap.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/LockedMap.cpp?rev=57374&r1=57373&r2=57374&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/LockedMap.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/LockedMap.cpp Sat Oct 11 07:54:38 2008
@@ -9,7 +9,6 @@
 
 #include <map>
 
-#include "JavaAllocator.h"
 #include "JavaArray.h"
 #include "JavaClass.h"
 #include "JavaString.h"

Modified: vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h?rev=57374&r1=57373&r2=57374&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/LockedMap.h Sat Oct 11 07:54:38 2008
@@ -16,6 +16,7 @@
 
 #include "types.h"
 
+#include "mvm/Allocator.h"
 #include "mvm/Object.h"
 #include "mvm/PrintBuffer.h"
 #include "mvm/Threads/Locks.h"
@@ -29,7 +30,6 @@
 namespace jnjvm {
 
 class JavaObject;
-class Allocator;
 
 struct ltutf8
 {
@@ -96,7 +96,7 @@
   typedef std::multimap<const uint32, const UTF8*>::iterator iterator;
   
   mvm::Lock* lock;
-  JavaAllocator* allocator;
+  mvm::Allocator* allocator;
   UserClassArray* array;
   std::multimap<const uint32, const UTF8*> map;
   const UTF8* lookupOrCreateAsciiz(const char* asciiz); 
@@ -104,7 +104,7 @@
   const UTF8* lookupAsciiz(const char* asciiz); 
   const UTF8* lookupReader(const uint16* buf, uint32 size);
   
-  UTF8Map(JavaAllocator* A, UserClassArray* cl) {
+  UTF8Map(mvm::Allocator* A, UserClassArray* cl) {
     lock = mvm::Lock::allocNormal();
     allocator = A;
     array = cl;
@@ -113,7 +113,7 @@
   ~UTF8Map() {
     delete lock;
     for (iterator i = map.begin(), e = map.end(); i!= e; ++i) {
-      delete(i->second);
+      allocator->freePermanentMemory((void*)i->second);
     }
   }
 

Modified: vmkit/trunk/lib/JnJVM/VMCore/Zip.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Zip.cpp?rev=57374&r1=57373&r2=57374&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Zip.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Zip.cpp Sat Oct 11 07:54:38 2008
@@ -9,17 +9,19 @@
 
 #include <zlib.h>
 
+#include <mvm/Allocator.h>
+
 #include "JavaArray.h"
 #include "Reader.h"
 #include "Zip.h"
 
 using namespace jnjvm;
 
-ZipArchive::ZipArchive(ArrayUInt8* bytes) {
+ZipArchive::ZipArchive(ArrayUInt8* bytes, mvm::Allocator* allocator) {
   this->bytes = bytes;
+  this->allocator = allocator,
   findOfscd();
-  if (ofscd > -1)
-    addFiles();
+  if (ofscd > -1) addFiles();
 }
 
 ZipFile* ZipArchive::getFile(const char* filename) {
@@ -123,7 +125,7 @@
 
   while (true) {
     if (memcmp(&(reader.bytes->elements[temp]), HDR_CENTRAL, 4)) return;
-    ZipFile* ptr = new ZipFile();
+    ZipFile* ptr = new(allocator) ZipFile();
     reader.cursor = temp + 4 + C_COMPRESSION_METHOD;
     ptr->compressionMethod = readEndianDep2(reader);
     
@@ -144,7 +146,8 @@
         (reader.max - temp) < ptr->filenameLength)
       return;
 
-    ptr->filename = (char*)malloc(ptr->filenameLength + 1);
+    ptr->filename = 
+      (char*)allocator->allocatePermanentMemory(ptr->filenameLength + 1);
     memcpy(ptr->filename, &(reader.bytes->elements[temp]), ptr->filenameLength);
     ptr->filename[ptr->filenameLength] = 0;
 

Modified: vmkit/trunk/lib/JnJVM/VMCore/Zip.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/Zip.h?rev=57374&r1=57373&r2=57374&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Zip.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Zip.h Sat Oct 11 07:54:38 2008
@@ -12,12 +12,14 @@
 
 #include <map>
 
+#include "mvm/Allocator.h"
+
 namespace jnjvm {
 
 class ArrayUInt8;
 class JnjvmBootstrapLoader;
 
-struct ZipFile {
+struct ZipFile : public mvm::PermanentObject {
   char* filename;
   int ucsize;
   int csize;
@@ -30,10 +32,12 @@
 
 
 
-class ZipArchive {
+class ZipArchive : public mvm::PermanentObject {
   friend class JnjvmBootstrapLoader;
 private:
   
+  mvm::Allocator* allocator;
+
   struct ltstr
   {
     bool operator()(const char* s1, const char* s2) const
@@ -57,13 +61,13 @@
   ~ZipArchive() {
     for (table_iterator I = filetable.begin(), E = filetable.end(); I != E; 
          ++I) {
-      free((void*)I->first);
-      delete I->second;
+      allocator->freePermanentMemory((void*)I->first);
+      delete(I->second, allocator);
     }
   }
 
   int getOfscd() { return ofscd; }
-  ZipArchive(ArrayUInt8* bytes);
+  ZipArchive(ArrayUInt8* bytes, mvm::Allocator* allocator);
   ZipFile* getFile(const char* filename);
   int readFile(ArrayUInt8* array, const ZipFile* file);
 





More information about the vmkit-commits mailing list