[vmkit-commits] [vmkit] r69042 - in /vmkit/trunk: include/jnjvm/JnjvmModule.h lib/JnJVM/Compiler/JavaAOTCompiler.cpp lib/JnJVM/Compiler/JavaJITCompiler.cpp lib/JnJVM/Compiler/JnjvmModule.cpp lib/JnJVM/VMCore/JavaClass.cpp lib/JnJVM/VMCore/JavaClass.h lib/JnJVM/VMCore/JavaInitialise.cpp lib/JnJVM/VMCore/JnjvmClassLoader.cpp lib/JnJVM/VMCore/JnjvmClassLoader.h

Nicolas Geoffray nicolas.geoffray at lip6.fr
Tue Apr 14 09:26:16 PDT 2009


Author: geoffray
Date: Tue Apr 14 11:26:15 2009
New Revision: 69042

URL: http://llvm.org/viewvc/llvm-project?rev=69042&view=rev
Log:
Remove all statically allocated internal classes and VT.


Modified:
    vmkit/trunk/include/jnjvm/JnjvmModule.h
    vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h

Modified: vmkit/trunk/include/jnjvm/JnjvmModule.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/jnjvm/JnjvmModule.h?rev=69042&r1=69041&r2=69042&view=diff

==============================================================================
--- vmkit/trunk/include/jnjvm/JnjvmModule.h (original)
+++ vmkit/trunk/include/jnjvm/JnjvmModule.h Tue Apr 14 11:26:15 2009
@@ -369,11 +369,6 @@
   
   bool enabledException;
   
-  /// allocateVT - Allocate a VT for the class. The VT will be the VT of
-  /// instances of the class.
-  void allocateVT(Class* cl);
-
-
   virtual void makeVT(Class* cl) = 0;
   
   

Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp?rev=69042&r1=69041&r2=69042&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Tue Apr 14 11:26:15 2009
@@ -33,17 +33,6 @@
 using namespace jnjvm;
 using namespace llvm;
 
-extern JavaVirtualTable JavaArrayVT;
-
-extern ClassArray ArrayOfBool;
-extern ClassArray ArrayOfByte;
-extern ClassArray ArrayOfChar;
-extern ClassArray ArrayOfShort;
-extern ClassArray ArrayOfInt;
-extern ClassArray ArrayOfFloat;
-extern ClassArray ArrayOfDouble;
-extern ClassArray ArrayOfLong;
-
 bool JavaAOTCompiler::isCompiling(const CommonClass* cl) const {
   if (cl->isClass()) {
     // A class is being static compiled if owner class is not null.
@@ -1113,7 +1102,7 @@
   const StructType* STy = StructType::get(Elemts);
   
   std::vector<Constant*> Cts;
-  Cts.push_back(CreateConstantForBaseObject(&ArrayOfChar));
+  Cts.push_back(CreateConstantForBaseObject(val->getClass()));
   Cts.push_back(ConstantInt::get(JnjvmModule::pointerSizeType, val->size));
   
   std::vector<Constant*> Vals;
@@ -1262,29 +1251,6 @@
   generateStubs = true;
   assumeCompiled = false;
 
-  const Type* ATy = JnjvmModule::JavaClassArrayType->getContainedType(0);
-  GlobalVariable* varGV = 0;
-  
-#define PRIMITIVE_ARRAY(name) \
-  varGV = new GlobalVariable(ATy, true, GlobalValue::ExternalLinkage, \
-                             0, #name, getLLVMModule()); \
-  arrayClasses.insert(std::make_pair(&name, varGV)); \
-  varGV = new GlobalVariable(JnjvmModule::VTType->getContainedType(0), true, \
-                             GlobalValue::ExternalLinkage, \
-                             0, #name"VT", getLLVMModule()); \
-  virtualTables.insert(std::make_pair(name.virtualVT, varGV));
-  
-  PRIMITIVE_ARRAY(ArrayOfBool)
-  PRIMITIVE_ARRAY(ArrayOfByte)
-  PRIMITIVE_ARRAY(ArrayOfChar)
-  PRIMITIVE_ARRAY(ArrayOfShort)
-  PRIMITIVE_ARRAY(ArrayOfInt)
-  PRIMITIVE_ARRAY(ArrayOfFloat)
-  PRIMITIVE_ARRAY(ArrayOfDouble)
-  PRIMITIVE_ARRAY(ArrayOfLong)
-
-#undef PRIMITIVE_ARRAY
-
   std::vector<const llvm::Type*> llvmArgs;
   llvmArgs.push_back(JnjvmModule::ptrType); // class loader.
   const FunctionType* FTy = FunctionType::get(Type::VoidTy, llvmArgs, false);
@@ -1462,18 +1428,11 @@
 
 void JavaAOTCompiler::makeVT(Class* cl) {
   internalMakeVT(cl);
-#ifndef WITHOUT_VTABLE
   VirtualTable* VT = cl->virtualVT;
   for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
     JavaMethod& meth = cl->virtualMethods[i];
     ((void**)VT)[meth.offset] = &meth;
   }
-
-  if (!cl->super) {
-    VT->destructor = 0;
-    ClassArray::initialiseVT();
-  }
-#endif 
 }
 
 void JavaAOTCompiler::setMethod(JavaMethod* meth, void* ptr, const char* name) {

Modified: vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp?rev=69042&r1=69041&r2=69042&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Tue Apr 14 11:26:15 2009
@@ -27,9 +27,6 @@
 using namespace jnjvm;
 using namespace llvm;
 
-extern JavaVirtualTable JavaArrayVT;
-extern JavaVirtualTable ArrayObjectVT;
-
 Constant* JavaJITCompiler::getNativeClass(CommonClass* classDef) {
   const llvm::Type* Ty = classDef->isClass() ? JnjvmModule::JavaClassType :
                                                JnjvmModule::JavaCommonClassType;
@@ -88,14 +85,13 @@
   assert(0 && "Should not be here");
   abort();
 #endif
-  void* obj = ((Class*)classDef)->getStaticInstance();
+  void* obj = classDef->getStaticInstance();
   if (!obj) {
-    Class* cl = (Class*)classDef;
     classDef->acquire();
-    obj = cl->getStaticInstance();
+    obj = classDef->getStaticInstance();
     if (!obj) {
       // Allocate now so that compiled code can reference it.
-      obj = cl->allocateStaticInstance(JavaThread::get()->getJVM());
+      obj = classDef->allocateStaticInstance(JavaThread::get()->getJVM());
     }
     classDef->release();
   }
@@ -140,10 +136,9 @@
 void JavaJITCompiler::makeVT(Class* cl) { 
   internalMakeVT(cl);
 
-#ifndef WITHOUT_VTABLE
-  JavaVirtualTable* VT = cl->virtualVT;
- 
-  assert(VT);
+  JavaVirtualTable* VT = cl->virtualVT; 
+  assert(VT && "No VT was allocated!");
+
   // Fill the virtual table with function pointers.
   ExecutionEngine* EE = mvm::MvmModule::executionEngine;
   for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
@@ -154,22 +149,14 @@
     // Special handling for finalize method. Don't put a finalizer
     // if there is none, or if it is empty.
     if (meth.offset == 0) {
-#if defined(ISOLATE_SHARING) || defined(USE_GC_BOEHM)
-      VT->destructor = 0;
-#else
-      Function* func = parseFunction(&meth);
+#if !defined(ISOLATE_SHARING) && !defined(USE_GC_BOEHM)
       if (!cl->super) {
         meth.canBeInlined = true;
-        VT->destructor = 0;
       } else {
-        Function::iterator BB = func->begin();
-        BasicBlock::iterator I = BB->begin();
-        if (isa<ReturnInst>(I)) {
-          VT->destructor = 0;
-        } else {
           // LLVM does not allow recursive compilation. Create the code now.
+          // TODO: improve this when we have proper initialization.
+          Function* func = parseFunction(&meth);
           VT->destructor = (uintptr_t)EE->getPointerToFunction(func);
-        }
       }
 #endif
     } else {
@@ -186,12 +173,6 @@
   func->deleteBody();
 #endif
     
-  // If there is no super, then it's the first VT that we allocate. Assign
-  // this VT to native types.
-  if (!(cl->super)) {
-    ClassArray::initialiseVT();
-  }
-#endif 
 }
 
 void JavaJITCompiler::setMethod(JavaMethod* meth, void* ptr, const char* name) {
@@ -232,5 +213,5 @@
   vm->waitForExit();
   
   delete newArgv;
-  return 0; 
+  return 0;
 }

Modified: vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp?rev=69042&r1=69041&r2=69042&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Tue Apr 14 11:26:15 2009
@@ -28,9 +28,6 @@
 using namespace jnjvm;
 using namespace llvm;
 
-
-extern JavaVirtualTable JavaObjectVT;
-
 #ifdef WITH_TRACER
 const llvm::FunctionType* JnjvmModule::MarkAndTraceType = 0;
 #endif
@@ -95,52 +92,6 @@
   enabledException = true;
 }
 
-#ifndef WITHOUT_VTABLE
-void JavaLLVMCompiler::allocateVT(Class* cl) {
-  for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
-    JavaMethod& meth = cl->virtualMethods[i];
-    if (meth.name->equals(cl->classLoader->bootstrapLoader->finalize)) {
-      meth.offset = 0;
-    } else {
-      JavaMethod* parent = cl->super? 
-        cl->super->lookupMethodDontThrow(meth.name, meth.type, false, true,
-                                         0) :
-        0;
-
-      uint64_t offset = 0;
-      if (!parent) {
-        offset = cl->virtualTableSize++;
-        meth.offset = offset;
-      } else {
-        offset = parent->offset;
-        meth.offset = parent->offset;
-      }
-    }
-  }
-
-  JavaVirtualTable* VT = 0;
-  if (cl->super) {
-    uint32 size = cl->virtualTableSize;
-    mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator;
-    Class* super = cl->super;
-    assert(cl->virtualTableSize >= super->virtualTableSize &&
-      "Super VT bigger than own VT");
-    assert(super->virtualVT && "Super does not have a VT!");
-    VT = new(allocator, size) JavaVirtualTable(cl);
-  } else {
-    VT = &JavaObjectVT;
-    VT->depth = 0;
-    VT->display = (JavaVirtualTable**)
-      cl->classLoader->allocator.Allocate(sizeof(JavaVirtualTable*));
-    VT->display[0] = VT;
-
-  }
-
-  cl->virtualVT = VT;
-}
-#endif
-
-
 #ifdef WITH_TRACER
 llvm::Function* JavaLLVMCompiler::internalMakeTracer(Class* cl, bool stat) {
   
@@ -228,27 +179,30 @@
 
 void JavaLLVMCompiler::internalMakeVT(Class* cl) {
   
-  JavaVirtualTable* VT = 0;
-#ifdef WITHOUT_VTABLE
-  mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator;
-  VT = (JavaVirtualTable*)allocator.Allocate(VT_SIZE);
-  memcpy(VT, JavaObjectVT, VT_SIZE);
-  cl->virtualVT = VT;
-#else
-  if (cl->super) {
-    if (isStaticCompiling() && !cl->super->virtualVT) {
-      makeVT(cl->super);
-    }
+  for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
+    JavaMethod& meth = cl->virtualMethods[i];
+    if (meth.name->equals(cl->classLoader->bootstrapLoader->finalize)) {
+      meth.offset = 0;
+    } else {
+      JavaMethod* parent = cl->super? 
+        cl->super->lookupMethodDontThrow(meth.name, meth.type, false, true,
+                                         0) :
+        0;
 
-    cl->virtualTableSize = cl->super->virtualTableSize;
-  } else {
-    cl->virtualTableSize = JavaVirtualTable::getFirstJavaMethodIndex();
+      uint64_t offset = 0;
+      if (!parent) {
+        offset = cl->virtualTableSize++;
+        meth.offset = offset;
+      } else {
+        offset = parent->offset;
+        meth.offset = parent->offset;
+      }
+    }
   }
 
-  // Allocate the virtual table.
-  allocateVT(cl);
-  VT = cl->virtualVT;
-#endif  
+  uint32 size = cl->virtualTableSize;
+  mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator;
+  cl->virtualVT = new(allocator, size) JavaVirtualTable(cl);
 }
 
 void JavaLLVMCompiler::resolveVirtualClass(Class* cl) {

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Tue Apr 14 11:26:15 2009
@@ -40,9 +40,8 @@
 Class* ClassArray::SuperArray;
 Class** ClassArray::InterfacesArray;
 
-extern JavaVirtualTable JavaObjectVT;
-
 extern "C" void JavaArrayTracer(JavaObject*);
+extern "C" void JavaObjectTracer(JavaObject*);
 extern "C" void ArrayObjectTracer(JavaObject*);
 
 Attribut::Attribut(const UTF8* name, uint32 length,
@@ -257,7 +256,7 @@
   }
 }
 
-void CommonClass::init(JnjvmClassLoader* loader, const UTF8* n) {
+CommonClass::CommonClass(JnjvmClassLoader* loader, const UTF8* n) {
   name = n;
   classLoader = loader;
   nbInterfaces = 0;
@@ -304,8 +303,8 @@
   memset(IsolateInfo, 0, sizeof(TaskClassMirror) * NR_ISOLATES);
 }
 
-void ClassArray::init(JnjvmClassLoader* loader, const UTF8* n,
-                      UserCommonClass* base) {
+ClassArray::ClassArray(JnjvmClassLoader* loader, const UTF8* n,
+                       UserCommonClass* base) : CommonClass(loader, n) {
   _baseClass = base;
   super = ClassArray::SuperArray;
   interfaces = ClassArray::InterfacesArray;
@@ -313,26 +312,6 @@
   
   uint32 size = JavaVirtualTable::getNumMethods();
   virtualVT = new(loader->allocator, size) JavaVirtualTable(this);
-  virtualVT->tracer = (uintptr_t)ArrayObjectTracer;
-  
-  depth = 1;
-  display = (CommonClass**)loader->allocator.Allocate(2 * sizeof(CommonClass*));
-  display[0] = ClassArray::SuperArray;
-  display[1] = this;
-  access = ACC_FINAL | ACC_ABSTRACT | ACC_PUBLIC | JNJVM_ARRAY;
-}
-
-void ClassArray::initPrimitive(JnjvmClassLoader* loader, const UTF8* n,
-                               UserCommonClass* base) {
-  CommonClass::init(loader, n);
-  
-  _baseClass = base;
-  super = ClassArray::SuperArray;
-  interfaces = ClassArray::InterfacesArray;
-  nbInterfaces = 2;
-  
-  virtualVT->tracer = (uintptr_t)JavaArrayTracer;
-  virtualVT->cl = this;
   
   depth = 1;
   display = (CommonClass**)loader->allocator.Allocate(2 * sizeof(CommonClass*));
@@ -796,6 +775,7 @@
     display = (CommonClass**)
       classLoader->allocator.Allocate(sizeof(CommonClass*));
     display[0] = this;
+    virtualTableSize = JavaVirtualTable::getFirstJavaMethodIndex();
   } else {
     super = classLoader->loadName(superUTF8, true, true);
     depth = super->depth + 1;
@@ -804,6 +784,7 @@
       allocator.Allocate(sizeof(CommonClass*) * (depth + 1));
     memcpy(display, super->display, depth * sizeof(UserCommonClass*));
     display[depth] = this;
+    virtualTableSize = super->virtualTableSize;
   }
 
   for (unsigned i = 0; i < realNbInterfaces; i++)
@@ -855,7 +836,7 @@
 
 Attribut* Class::readAttributs(Reader& reader, uint16& size) {
   uint16 nba = reader.readU2();
-  
+ 
   Attribut* attributs = new(classLoader->allocator) Attribut[nba];
 
   for (int i = 0; i < nba; i++) {
@@ -974,6 +955,7 @@
       if (!needsInitialisationCheck()) {
         setInitializationState(ready);
       }
+      if (!super) ClassArray::initialiseVT();
       setOwnerClass(0);
       broadcastClass();
       release();
@@ -1312,47 +1294,91 @@
     COPY(upcalls->ArrayOfFloat)
     COPY(upcalls->ArrayOfDouble)
     COPY(upcalls->ArrayOfLong)
-    COPY(upcalls->ArrayOfObject)
-    COPY(upcalls->ArrayOfString)
 
 #undef COPY
-
+ 
+  JnjvmClassLoader* JCL = cl->classLoader;
+  // Load array classes that JnJVM internally uses.
+  upcalls->ArrayOfString = 
+    JCL->constructArray(JCL->asciizConstructUTF8("[Ljava/lang/String;"));
+  
+  upcalls->ArrayOfObject = 
+    JCL->constructArray(JCL->asciizConstructUTF8("[Ljava/lang/Object;"));
 }
 
 JavaVirtualTable::JavaVirtualTable(Class* C) {
+   
+  if (C->super) {
+    // (1) Copy the super VT into the current VT.
+    uint32 size = C->super->virtualTableSize * sizeof(uintptr_t);
+    memcpy(this, C->super->virtualVT, size);
+  
+    // (2) Set the class of this VT.
+    cl = C;
     
-  // (1) Copy the super VT into the current VT.
-  uint32 size = C->super->virtualTableSize * sizeof(uintptr_t);
-  memcpy(this, C->super->virtualVT, size);
+    // (3) Set depth and display for fast dynamic type checking.
+    depth = C->super->virtualVT->depth + 1;
+    mvm::BumpPtrAllocator& allocator = C->classLoader->allocator;
+    display = (JavaVirtualTable**)
+      allocator.Allocate(sizeof(JavaVirtualTable*) * (depth + 1));   
+    size = depth * sizeof(JavaVirtualTable*);
+    memcpy(display, C->super->virtualVT->display, size); 
+    display[depth] = this;
+  } else {
+    // (1) Set the tracer, destructor and delete
+    tracer = (uintptr_t)JavaObjectTracer;
+    destructor = 0;
+    operatorDelete = 0;
+    
+    // (2) Set the class of this VT.
+    cl = C;
+    
+    // (3) Set depth and display for fast dynamic type checking.
+    depth = 0;
+    display = (JavaVirtualTable**)
+      C->classLoader->allocator.Allocate(sizeof(JavaVirtualTable*));
+    display[0] = this;
+    destructor = 0;
+  }
     
-  // (2) Set the class of this VT.
-  cl = C;
 
-  // (3) Set depth and display for fast dynamic type checking.
-  depth = cl->super->virtualVT->depth + 1;
-  mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator;
-  display = (JavaVirtualTable**)
-    allocator.Allocate(sizeof(JavaVirtualTable*) * (depth + 1));   
-  size = depth * sizeof(JavaVirtualTable*);
-  memcpy(display, cl->super->virtualVT->display, size); 
-  display[depth] = this;
 }
   
 JavaVirtualTable::JavaVirtualTable(ClassArray* C) {
+   
+  if (!C->baseClass()->isPrimitive()) {
+    // (1) Copy the super VT into the current VT.
+    uint32 size = getNumMethods() * sizeof(uintptr_t);
+    memcpy(this, C->super->virtualVT, size);
+    tracer = (uintptr_t)ArrayObjectTracer;
     
-  // (1) Copy the super VT into the current VT.
-  uint32 size = getNumMethods() * sizeof(uintptr_t);
-  memcpy(this, &JavaObjectVT, size);
-    
-  // (2) Set the class of this VT.
-  cl = C;
+    // (2) Set the class of this VT.
+    cl = C;
 
-  // (3) Set depth and display for fast dynamic type checking.
-  depth = 1;
-  mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator;
-  display = 
-    (JavaVirtualTable**)allocator.Allocate(sizeof(JavaVirtualTable*) * 2);
-  display[0] = &JavaObjectVT;
-  display[1] = this;
+    // (3) Set depth and display for fast dynamic type checking.
+    depth = 1;
+    mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator;
+    display = 
+      (JavaVirtualTable**)allocator.Allocate(sizeof(JavaVirtualTable*) * 2);
+    display[0] = C->super->virtualVT;
+    display[1] = this;
+  } else {
+    // (1) Set the tracer, destructor and delete
+    tracer = (uintptr_t)JavaArrayTracer;
+    destructor = 0;
+    operatorDelete = 0;
+    
+    // (2) Set the class of this VT.
+    cl = C;
+    
+    // (3) Set depth and display for fast dynamic type checking. Since
+    // JavaObject has not been loaded yet, don't use super.
+    depth = 1;
+    mvm::BumpPtrAllocator& allocator = cl->classLoader->allocator;
+    display = 
+      (JavaVirtualTable**)allocator.Allocate(sizeof(JavaVirtualTable*) * 2);
+    display[0] = 0;
+    display[1] = this;
+  }
 }
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Tue Apr 14 11:26:15 2009
@@ -305,9 +305,7 @@
   
   /// CommonClass - Create a class with th given name.
   ///
-  CommonClass(JnjvmClassLoader* loader, const UTF8* name) {
-    init(loader, name);
-  }
+  CommonClass(JnjvmClassLoader* loader, const UTF8* name);
   
   /// ~CommonClass - Free memory used by this class, and remove it from
   /// metadata.
@@ -318,10 +316,6 @@
   ///
   CommonClass();
   
-  /// init - initialize the class.
-  ///
-  void init(JnjvmClassLoader* JCL, const UTF8* n);
-  
   /// setInterfaces - Set the interfaces of the class.
   ///
   void setInterfaces(Class** I) {
@@ -911,26 +905,10 @@
   ///
   JavaArray* doNew(sint32 n, Jnjvm* vm);
 
-  /// init - Initialize the array class.
-  ///
-  void init(JnjvmClassLoader* loader, const UTF8* name,
-            UserCommonClass* baseClass);
-  
-  /// initPrimitive - Initialize the primitive array class.
-  ///
-  void initPrimitive(JnjvmClassLoader* loader, const UTF8* name,
-                     UserCommonClass* baseClass);
-
-  /// ClassArray - Constructor with a VT.
-  ///
-  ClassArray(JavaVirtualTable& VT) { virtualVT = &VT; }
-
   /// ClassArray - Construct a Java array class with the given name.
   ///
   ClassArray(JnjvmClassLoader* loader, const UTF8* name,
-             UserCommonClass* baseClass) : CommonClass (loader, name) {
-    init(loader, name, baseClass);
-  }
+             UserCommonClass* baseClass);
   
   /// SuperArray - The super of class arrays. Namely java/lang/Object.
   ///

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp Tue Apr 14 11:26:15 2009
@@ -23,8 +23,6 @@
 using namespace jnjvm;
 
 
-JavaVirtualTable JavaObjectVT;
-
 static void initialiseVT() {
 
 # define INIT(X) { \
@@ -43,14 +41,6 @@
 #endif
 #undef INIT
 
-#define INIT(X) { \
-  X fake; \
-  void* V = ((void**)(void*)(&fake))[0]; \
-  memcpy(&(X##VT), V, sizeof(VirtualTable)); \
-  X##VT.destructor = 0; }
-
-  INIT(JavaObject);
-#undef INIT
 }
 
 #ifdef ISOLATE_SHARING

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Tue Apr 14 11:26:15 2009
@@ -52,26 +52,6 @@
 
 using namespace jnjvm;
 
-JavaVirtualTable ArrayOfBoolVT;
-JavaVirtualTable ArrayOfByteVT;
-JavaVirtualTable ArrayOfCharVT;
-JavaVirtualTable ArrayOfShortVT;
-JavaVirtualTable ArrayOfIntVT;
-JavaVirtualTable ArrayOfFloatVT;
-JavaVirtualTable ArrayOfDoubleVT;
-JavaVirtualTable ArrayOfLongVT;
-
-ClassArray ArrayOfBool(ArrayOfBoolVT);
-ClassArray ArrayOfByte(ArrayOfByteVT);
-ClassArray ArrayOfChar(ArrayOfCharVT);
-ClassArray ArrayOfShort(ArrayOfShortVT);
-ClassArray ArrayOfInt(ArrayOfIntVT);
-ClassArray ArrayOfFloat(ArrayOfFloatVT);
-ClassArray ArrayOfDouble(ArrayOfDoubleVT);
-ClassArray ArrayOfLong(ArrayOfLongVT);
-
-extern "C" void JavaArrayTracer(JavaObject*);
-
 typedef void (*static_init_t)(JnjvmClassLoader*);
 
 JnjvmBootstrapLoader::JnjvmBootstrapLoader(mvm::BumpPtrAllocator& Alloc,
@@ -117,36 +97,28 @@
   upcalls->OfByte = UPCALL_PRIMITIVE_CLASS(this, "byte", 1);
   
   // Create the primitive arrays.
-  upcalls->ArrayOfChar = constructPrimitiveArray(ArrayOfChar,
-                                                 asciizConstructUTF8("[C"),
+  upcalls->ArrayOfChar = constructPrimitiveArray(asciizConstructUTF8("[C"),
                                                  upcalls->OfChar);
 
-  upcalls->ArrayOfByte = constructPrimitiveArray(ArrayOfByte,
-                                                 asciizConstructUTF8("[B"),
+  upcalls->ArrayOfByte = constructPrimitiveArray(asciizConstructUTF8("[B"),
                                                  upcalls->OfByte);
   
-  upcalls->ArrayOfInt = constructPrimitiveArray(ArrayOfInt,
-                                                asciizConstructUTF8("[I"),
+  upcalls->ArrayOfInt = constructPrimitiveArray(asciizConstructUTF8("[I"),
                                                 upcalls->OfInt);
   
-  upcalls->ArrayOfBool = constructPrimitiveArray(ArrayOfBool,
-                                                 asciizConstructUTF8("[Z"),
+  upcalls->ArrayOfBool = constructPrimitiveArray(asciizConstructUTF8("[Z"),
                                                  upcalls->OfBool);
   
-  upcalls->ArrayOfLong = constructPrimitiveArray(ArrayOfLong,
-                                                 asciizConstructUTF8("[J"),
+  upcalls->ArrayOfLong = constructPrimitiveArray(asciizConstructUTF8("[J"),
                                                  upcalls->OfLong);
   
-  upcalls->ArrayOfFloat = constructPrimitiveArray(ArrayOfFloat,
-                                                  asciizConstructUTF8("[F"),
+  upcalls->ArrayOfFloat = constructPrimitiveArray(asciizConstructUTF8("[F"),
                                                   upcalls->OfFloat);
   
-  upcalls->ArrayOfDouble = constructPrimitiveArray(ArrayOfDouble,
-                                                   asciizConstructUTF8("[D"),
+  upcalls->ArrayOfDouble = constructPrimitiveArray(asciizConstructUTF8("[D"),
                                                    upcalls->OfDouble);
   
-  upcalls->ArrayOfShort = constructPrimitiveArray(ArrayOfShort,
-                                                  asciizConstructUTF8("[S"),
+  upcalls->ArrayOfShort = constructPrimitiveArray(asciizConstructUTF8("[S"),
                                                   upcalls->OfShort);
   
   // Fill the maps.
@@ -179,25 +151,31 @@
   // Now that native types have been loaded, try to find if we have a
   // pre-compiled rt.jar
   if (dlLoad) {
-    nativeHandle = dlopen("libvmjc"DYLD_EXTENSION, RTLD_LAZY | RTLD_GLOBAL);
-    if (nativeHandle) {
-      // Found it!
-      SuperArray = (Class*)dlsym(nativeHandle, "java.lang.Object");
+    SuperArray = (Class*)dlsym(SELF_HANDLE, "java.lang.Object");
+    if (!SuperArray) {
+      nativeHandle = dlopen("libvmjc"DYLD_EXTENSION, RTLD_LAZY | RTLD_GLOBAL);
+      if (nativeHandle) {
+        // Found it!
+        SuperArray = (Class*)dlsym(nativeHandle, "java.lang.Object");
+      }
+    }
     
-      if (SuperArray) {
-        ClassArray::SuperArray = (Class*)SuperArray->getInternal();
-        // We have the java/lang/Object class, execute the static initializer.
-        static_init_t init = (static_init_t)(uintptr_t)SuperArray->classLoader;
-        assert(init && "Loaded the wrong boot library");
-        init(this);
-        ClassArray::initialiseVT();
-      } 
+    if (SuperArray) {
+      ClassArray::SuperArray = (Class*)SuperArray->getInternal();
+      // We have the java/lang/Object class, execute the static initializer.
+      static_init_t init = (static_init_t)(uintptr_t)SuperArray->classLoader;
+      assert(init && "Loaded the wrong boot library");
+      init(this);
+      ClassArray::initialiseVT();
     }
   }
     
   // We haven't found a pre-compiled rt.jar, load the root class ourself.
   if (!SuperArray) {
-    
+   
+    // We can not resolve java.lang.Object yet, because we may not be
+    // running in a Java thread, and we may not have a compiler
+    // available.
     SuperArray = loadName(asciizConstructUTF8("java/lang/Object"), false,
                           false);
     ClassArray::SuperArray = (Class*)SuperArray->getInternal();
@@ -213,13 +191,6 @@
   
   ClassArray::InterfacesArray[0] = (Class*)InterfacesArray[0]->getInternal();
   ClassArray::InterfacesArray[1] = (Class*)(InterfacesArray[1]->getInternal()); 
- 
-  // Load array classes that JnJVM internally uses.
-  upcalls->ArrayOfString = 
-    constructArray(asciizConstructUTF8("[Ljava/lang/String;"));
-  
-  upcalls->ArrayOfObject = 
-    constructArray(asciizConstructUTF8("[Ljava/lang/Object;"));
   
  
   Attribut::codeAttribut = asciizConstructUTF8("Code");
@@ -626,12 +597,12 @@
 }
 
 ClassArray* 
-JnjvmBootstrapLoader::constructPrimitiveArray(ClassArray& cl, const UTF8* name,
+JnjvmBootstrapLoader::constructPrimitiveArray(const UTF8* name,
                                               ClassPrimitive* baseClass) {
     
-  cl.initPrimitive(this, name, baseClass);
-  classes->map.insert(std::make_pair(name, &cl));
-  return &cl;
+  ClassArray* cl = new(allocator) UserClassArray(this, name, baseClass);
+  classes->map.insert(std::make_pair(name, cl));
+  return cl;
 }
 
 Typedef* JnjvmClassLoader::internalConstructType(const UTF8* name) {

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Tue Apr 14 11:26:15 2009
@@ -289,7 +289,7 @@
   
   /// constructPrimitiveArray - Hashes the primitive array.
   ///
-  ClassArray* constructPrimitiveArray(ClassArray& cl, const UTF8* name,
+  ClassArray* constructPrimitiveArray(const UTF8* name,
                                       ClassPrimitive* prim);
 
 public:





More information about the vmkit-commits mailing list