[vmkit-commits] [vmkit] r70842 - in /vmkit/trunk: include/jnjvm/ include/mvm/ include/mvm/GC/ lib/JnJVM/Classpath/ lib/JnJVM/Compiler/ lib/JnJVM/VMCore/ lib/Mvm/BoehmGC/ lib/Mvm/GCMmap2/ lib/Mvm/Runtime/ tools/jnjvm/ tools/n3-mono/ tools/n3-pnetlib/ tools/vmjc/ tools/vmkit/

Nicolas Geoffray nicolas.geoffray at lip6.fr
Mon May 4 00:42:10 PDT 2009


Author: geoffray
Date: Mon May  4 02:42:08 2009
New Revision: 70842

URL: http://llvm.org/viewvc/llvm-project?rev=70842&view=rev
Log:
Revert to r69997, something was wrong with the finalization support.


Modified:
    vmkit/trunk/include/jnjvm/JnjvmModule.h
    vmkit/trunk/include/mvm/GC/GC.h
    vmkit/trunk/include/mvm/Object.h
    vmkit/trunk/include/mvm/PrintBuffer.h
    vmkit/trunk/include/mvm/VirtualMachine.h
    vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h
    vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClassLoader.cpp
    vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp
    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/JavaMetaJIT.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaString.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.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/VirtualTables.cpp
    vmkit/trunk/lib/Mvm/BoehmGC/MvmGC.h
    vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h
    vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp
    vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp
    vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h
    vmkit/trunk/lib/Mvm/Runtime/Object.cpp
    vmkit/trunk/tools/jnjvm/Main.cpp
    vmkit/trunk/tools/n3-mono/Main.cpp
    vmkit/trunk/tools/n3-pnetlib/Main.cpp
    vmkit/trunk/tools/vmjc/vmjc.cpp
    vmkit/trunk/tools/vmkit/Launcher.cpp

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

==============================================================================
--- vmkit/trunk/include/jnjvm/JnjvmModule.h (original)
+++ vmkit/trunk/include/jnjvm/JnjvmModule.h Mon May  4 02:42:08 2009
@@ -234,7 +234,6 @@
 #ifdef WITH_TRACER
   llvm::Function* MarkAndTraceFunction;
   static const llvm::FunctionType* MarkAndTraceType;
-  llvm::Function* EmptyTracerFunction;  
   llvm::Function* JavaObjectTracerFunction;  
   llvm::Function* JavaArrayTracerFunction;  
   llvm::Function* ArrayObjectTracerFunction;  
@@ -359,7 +358,9 @@
 
 #ifdef WITH_TRACER 
   llvm::Function* internalMakeTracer(Class* cl, bool stat);
-  virtual llvm::Function* makeTracer(Class* cl, bool stat)  = 0;
+  virtual llvm::Function* makeTracer(Class* cl, bool stat) {
+    return internalMakeTracer(cl, stat);
+  }
 #endif
   
   void addJavaPasses();
@@ -501,10 +502,6 @@
 #ifdef SERVICE
   virtual llvm::Value* getIsolate(Jnjvm* vm, llvm::Value* Where);
 #endif
-
-#ifdef WITH_TRACER
-  virtual llvm::Function* makeTracer(Class* cl, bool stat);
-#endif
   
   virtual ~JavaJITCompiler() {}
   

Modified: vmkit/trunk/include/mvm/GC/GC.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/GC/GC.h?rev=70842&r1=70841&r2=70842&view=diff

==============================================================================
--- vmkit/trunk/include/mvm/GC/GC.h (original)
+++ vmkit/trunk/include/mvm/GC/GC.h Mon May  4 02:42:08 2009
@@ -23,16 +23,6 @@
   uintptr_t* getFunctions() {
     return &destructor;
   }
-
-  VirtualTable(uintptr_t d, uintptr_t o, uintptr_t t) {
-    destructor = d;
-    operatorDelete = o;
-    tracer = t;
-  }
-
-  VirtualTable() {}
-
-  static void emptyTracer(void*) {}
 };
 
 class gcRoot {
@@ -64,10 +54,7 @@
   VirtualTable *_XXX_vt;
   inline gcRoot *_2gc() { return (gcRoot *)this; }
   destructor_t getDestructor() {
-    return (destructor_t)this->_XXX_vt->destructor;
-  }
-  destructor_t getDelete() {
-    return (destructor_t)this->_XXX_vt->operatorDelete;
+    return ((destructor_t*)(this->_XXX_vt))[0];
   }
 };
 

Modified: vmkit/trunk/include/mvm/Object.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Object.h?rev=70842&r1=70841&r2=70842&view=diff

==============================================================================
--- vmkit/trunk/include/mvm/Object.h (original)
+++ vmkit/trunk/include/mvm/Object.h Mon May  4 02:42:08 2009
@@ -50,6 +50,12 @@
   ///
   virtual intptr_t  hashCode(){ return (intptr_t)this;}
   
+  /// initialise - All virtual machines must call Object::initialise to
+  /// property initialise the PrintBuffer and NativeString classes. These
+  /// classes are mainly used for debugging but also for object hashing.
+  ///
+  static void initialise();
+
 };
 
 } // end namespace mvm

Modified: vmkit/trunk/include/mvm/PrintBuffer.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/PrintBuffer.h?rev=70842&r1=70841&r2=70842&view=diff

==============================================================================
--- vmkit/trunk/include/mvm/PrintBuffer.h (original)
+++ vmkit/trunk/include/mvm/PrintBuffer.h Mon May  4 02:42:08 2009
@@ -10,8 +10,8 @@
 #ifndef MVM_PRINTBUFFER_H
 #define MVM_PRINTBUFFER_H
 
-#include <cstdio> // sprintf
-#include <cstring> // memcpy
+#include <stdio.h> // sprintf
+#include <string.h> // memcpy
 
 #include "types.h"
 #include "mvm/Object.h"
@@ -22,12 +22,12 @@
 /// NativeString - This class is the equivalent of a char*, but allocated
 /// by the GC, hence has a virtual table.
 ///
-class NativeString : public gc {
+class NativeString : public Object {
 public:
   
   /// VT - The virtual table of this class.
   ///
-  static VirtualTable VT;
+  static VirtualTable* VT;
 
   /// cString - Returns the C equivalent of the NativeString.
   ///
@@ -44,7 +44,7 @@
   /// alloc - Allocates a NativeString of size len.
   ///
   static inline NativeString *alloc(size_t len) {
-    return (NativeString *)gc::operator new(len + sizeof(VirtualTable*), &VT);
+    return (NativeString *)gc::operator new(len + sizeof(VirtualTable*), VT);
   }
 
   /// realloc - Reallocate a native string of size len.
@@ -69,7 +69,7 @@
 
 /// PrintBuffer - This class is a buffered string.
 ///
-class PrintBuffer : public gc {
+class PrintBuffer : public Object {
 private:
  
   /// _contents - The buffer.
@@ -90,7 +90,7 @@
   
   /// VT - The virtual table of this class.
   ///
-  static VirtualTable VT;
+  static VirtualTable* VT;
   
   
   /// contents - Returns the buffer.
@@ -179,7 +179,7 @@
   /// alloc - Allocates a default PrintBuffer.
   ///
   static PrintBuffer *alloc(void) {
-    PrintBuffer* pbf = (PrintBuffer*)gc::operator new(sizeof(PrintBuffer), &VT);
+    PrintBuffer* pbf = gc_new(PrintBuffer)();
     pbf->capacity= 32;
     pbf->writePosition= 0;
     pbf->setContents(NativeString::alloc(pbf->capacity));
@@ -188,9 +188,7 @@
 
   /// tracer - Traces this PrintBuffer.
   ///
-  static void STATIC_TRACER(PrintBuffer) {
-    obj->contents()->MARK_AND_TRACE;
-  }
+  virtual void TRACER;
 };
 
 } // end namespace mvm

Modified: vmkit/trunk/include/mvm/VirtualMachine.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/VirtualMachine.h?rev=70842&r1=70841&r2=70842&view=diff

==============================================================================
--- vmkit/trunk/include/mvm/VirtualMachine.h (original)
+++ vmkit/trunk/include/mvm/VirtualMachine.h Mon May  4 02:42:08 2009
@@ -18,23 +18,11 @@
 #include "mvm/Allocator.h"
 #include "mvm/CompilationUnit.h"
 #include "mvm/Object.h"
-#include "mvm/Threads/Cond.h"
 #include "mvm/Threads/Locks.h"
 
 #include <cassert>
 #include <map>
 
-
-// Same values than JikesRVM
-#define INITIAL_QUEUE_SIZE 256
-#define GROW_FACTOR 2
-
-#if (__WORDSIZE == 64)
-#define LOG_BYTES_IN_ADDRESS 3
-#else
-#define LOG_BYTES_IN_ADDRESS 2
-#endif
-
 namespace jnjvm {
   class JavaCompiler;
   class JnjvmClassLoader;
@@ -42,57 +30,13 @@
 
 namespace mvm {
 
-class VirtualMachine;
-
-class ReferenceQueue {
-private:
-  gc** References;
-  uint32 QueueLength;
-  uint32 CurrentIndex;
-  mvm::SpinLock QueueLock;
-  uint8_t semantics;
-
-  gc* processReference(gc*, VirtualMachine*);
-public:
-
-  static const uint8_t WEAK = 1;
-  static const uint8_t SOFT = 2;
-  static const uint8_t PHANTOM = 3;
-
-  ReferenceQueue(uint8_t s) {
-    References = new gc*[INITIAL_QUEUE_SIZE];
-    QueueLength = INITIAL_QUEUE_SIZE;
-    CurrentIndex = 0;
-    semantics = s;
-  }
- 
-  void addReference(gc* ref) {
-    QueueLock.acquire();
-    if (CurrentIndex >= QueueLength) {
-      uint32 newLength = QueueLength * GROW_FACTOR;
-      gc** newQueue = new gc*[newLength];
-      for (uint32 i = 0; i < QueueLength; ++i) newQueue[i] = References[i];
-      delete[] References;
-      References = newQueue;
-      QueueLength = newLength;
-    }
-    References[CurrentIndex++] = ref;
-    QueueLock.release();
-  }
-
-  void scan(VirtualMachine* vm);
-};
-
 /// VirtualMachine - This class is the root of virtual machine classes. It
 /// defines what a VM should be.
 ///
 class VirtualMachine : public mvm::PermanentObject {
 protected:
 
-  VirtualMachine() : 
-    WeakReferencesQueue(ReferenceQueue::WEAK),
-    SoftReferencesQueue(ReferenceQueue::SOFT), 
-    PhantomReferencesQueue(ReferenceQueue::PHANTOM) {
+  VirtualMachine() {
 #ifdef SERVICE
     memoryLimit = ~0;
     executionLimit = ~0;
@@ -102,13 +46,6 @@
     status = 1;
     _since_last_collection = 4*1024*1024;
 #endif
-    
-    FinalizationQueue = new gc*[INITIAL_QUEUE_SIZE];
-    QueueLength = INITIAL_QUEUE_SIZE;
-    
-    ToBeFinalized = new gc*[INITIAL_QUEUE_SIZE];
-    ToBeFinalizedLength = INITIAL_QUEUE_SIZE;
-
   }
 public:
 
@@ -165,162 +102,6 @@
     return (T*)I->second;
   }
 
-private:
-  /// FinalizationQueueLock - A lock to protect access to the queue.
-  ///
-  mvm::SpinLock FinalizationQueueLock;
-
-  /// finalizationQueue - A list of allocated objets that contain a finalize
-  /// method.
-  ///
-  gc** FinalizationQueue;
-
-  /// CurrentIndex - Current index in the queue of finalizable objects.
-  ///
-  uint32 CurrentIndex;
-
-  /// QueueLength - Current length of the queue of finalizable objects.
-  ///
-  uint32 QueueLength;
-
-  /// growQueue - Grow the queue of finalizable objects.
-  ///
-  void growQueue();
-  
-  /// ToBeFinalized - List of objects that are scheduled to be finalized.
-  ///
-  gc** ToBeFinalized;
-  
-  /// ToBeFinalizedLength - Current length of the queue of objects scheduled
-  /// for finalization.
-  ///
-  uint32 ToBeFinalizedLength;
-
-  /// CurrentFinalizedIndex - The current index in the ToBeFinalized queue
-  /// that will be sceduled for finalization.
-  ///
-  uint32 CurrentFinalizedIndex;
-  
-  /// LastFinalizedIndex - The last index in the ToBeFinalized queue whose
-  /// finalize method has been called.
-  ///
-  uint32 LastFinalizedIndex;
-  
-  /// finalizationCond - Condition variable to wake up finalization threads.
-  ///
-  mvm::Cond FinalizationCond;
-
-  /// finalizationLock - Lock for the condition variable.
-  ///
-  mvm::LockNormal FinalizationLock;
-
-  /// countFinalized - The number of entries to be finalized.
-  ///
-  uint32 countFinalized() {
-    return (LastFinalizedIndex - CurrentFinalizedIndex + ToBeFinalizedLength) 
-      % ToBeFinalizedLength;
-  }
-
-  /// freeFinalized - The number of entries available in the ToBeFinalized
-  /// queue.
-  ///
-  uint32 freeFinalized() {
-    return ToBeFinalizedLength - countFinalized();
-  }
-
-  /// WeakReferencesQueue - The queue of weak references.
-  ///
-  ReferenceQueue WeakReferencesQueue;
-
-  /// SoftReferencesQueue - The queue of soft references.
-  ///
-  ReferenceQueue SoftReferencesQueue;
-
-  /// PhantomReferencesQueue - The queue of phantom references.
-  ///
-  ReferenceQueue PhantomReferencesQueue;
-
-protected:
-  /// invokeFinalizer - Invoke the finalizer of the object. This may involve
-  /// changing the environment, e.g. going to native to Java.
-  ///
-  virtual void invokeFinalizer(gc*) {}
-
-
-public:
-  /// finalizerStart - The start function of a finalizer. Will poll the
-  /// finalizationQueue.
-  ///
-  static void finalizerStart(mvm::Thread*);
-
-  /// addFinalizationCandidate - Add an object to the queue of objects with
-  /// a finalization method.
-  ///
-  void addFinalizationCandidate(gc*);
-  
-  /// scanFinalizationQueue - Scan objets with a finalized method and schedule
-  /// them for finalization if they are not live.
-  ///
-  void scanFinalizationQueue();
-
-  /// wakeUpFinalizers - Wake the finalizers.
-  ///
-  void wakeUpFinalizers() { FinalizationCond.broadcast(); }
-
-  /// scanWeakReferencesQueue - Scan all weak references. Called by the GC
-  /// before scanning the finalization queue.
-  /// 
-  void scanWeakReferencesQueue() {
-    WeakReferencesQueue.scan(this);
-  }
-  
-  /// scanSoftReferencesQueue - Scan all soft references. Called by the GC
-  /// before scanning the finalization queue.
-  ///
-  void scanSoftReferencesQueue() {
-    SoftReferencesQueue.scan(this);
-  }
-  
-  /// scanPhantomReferencesQueue - Scan all phantom references. Called by the GC
-  /// after the finalization queue.
-  ///
-  void scanPhantomReferencesQueue() {
-    PhantomReferencesQueue.scan(this);
-  }
-  
-  /// addWeakReference - Add a weak reference to the queue.
-  ///
-  void addWeakReference(gc* ref) {
-    WeakReferencesQueue.addReference(ref);
-  }
-  
-  /// addSoftReference - Add a weak reference to the queue.
-  ///
-  void addSoftReference(gc* ref) {
-    SoftReferencesQueue.addReference(ref);
-  }
-  
-  /// addPhantomReference - Add a weak reference to the queue.
-  ///
-  void addPhantomReference(gc* ref) {
-    PhantomReferencesQueue.addReference(ref);
-  }
-
-  /// clearReferent - Clear the referent in a reference. Should be overriden
-  /// by the VM.
-  ///
-  virtual void clearReferent(gc*) {}
-
-  /// getReferent - Get the referent of the reference. Should be overriden
-  /// by the VM.
-  //
-  virtual gc* getReferent(gc*) { return 0; }
-
-  /// enqueueReference - Calls the enqueue method. Should be overriden
-  /// by the VM.
-  ///
-  virtual bool enqueueReference(gc*) { return false; }
-
 #ifdef ISOLATE
   size_t IsolateID;
 #endif

Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h?rev=70842&r1=70841&r2=70842&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h Mon May  4 02:42:08 2009
@@ -148,27 +148,6 @@
   }
 };
 
-class JavaObjectReference : public JavaObject {
-private:
-  JavaObject* referent;
-  JavaObject* queue;
-  JavaObject* nextOnQueue;
-
-public:
-  void init(JavaObject* r, JavaObject* q) {
-    referent = r;
-    queue = q;
-  }
-
-  JavaObject* getReferent() const { return referent; }
-  void setReferent(JavaObject* r) { referent = r; }
-  
-  static void STATIC_TRACER(JavaObjectReference) {
-    obj->queue->MARK_AND_TRACE;
-    obj->nextOnQueue->MARK_AND_TRACE;
-  }
-};
-
 }
 
 #endif

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClassLoader.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMClassLoader.cpp Mon May  4 02:42:08 2009
@@ -129,6 +129,7 @@
   
   if (!cl) {
     UserClass* cl = JCL->constructClass(name, (ArrayUInt8*)bytes);
+    cl->resolveClass();
 
     res = (jclass)(cl->getClassDelegatee(vm, (JavaObject*)pd));
   } else {

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JITInfo.cpp Mon May  4 02:42:08 2009
@@ -106,8 +106,14 @@
     uint64 size = JnjvmModule::getTypeSize(structType);
     cl->staticSize = size;
 #ifdef WITH_TRACER
-    JavaLLVMCompiler* Mod = (JavaLLVMCompiler*)cl->classLoader->getCompiler();
-    staticTracerFunction = Mod->makeTracer(cl, true);
+    JavaLLVMCompiler* Mod = 
+      (JavaLLVMCompiler*)cl->classLoader->getCompiler();
+    if (!Mod->isStaticCompiling()) {
+      Function* F = Mod->makeTracer(cl, true);
+      cl->staticTracer = (void (*)(void*)) (uintptr_t)
+        JnjvmModule::executionEngine->getPointerToFunction(F);
+      F->deleteBody();
+    }
 #endif
   }
   return staticType;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaAOTCompiler.cpp Mon May  4 02:42:08 2009
@@ -1016,9 +1016,6 @@
   // innerOuterResolved
   ClassElts.push_back(ConstantInt::get(Type::Int8Ty, cl->innerOuterResolved));
   
-  // isAnonymous
-  ClassElts.push_back(ConstantInt::get(Type::Int8Ty, cl->isAnonymous));
-  
   // virtualTableSize
   ClassElts.push_back(ConstantInt::get(Type::Int32Ty, cl->virtualTableSize));
   
@@ -1031,8 +1028,7 @@
   // staticTracer
   const Type* FTy = STy->getContainedType(STy->getNumContainedTypes() - 1);
 #ifdef WITH_TRACER
-  Function* F = getClassInfo(cl)->getStaticTracer();
-  assert(F && "No static tracer");
+  Function* F = makeTracer(cl, true);
   Constant* staticTracer = ConstantExpr::getCast(Instruction::BitCast, F, FTy);
 #else
   Constant* staticTracer = ConstantExpr::getNullValue(FTy);
@@ -1157,7 +1153,7 @@
       Tracer = JavaIntrinsics.ArrayObjectTracerFunction;
     }
   } else if (classDef->isClass()) {
-    Tracer = getClassInfo(classDef->asClass())->getVirtualTracer();
+    Tracer = makeTracer(classDef->asClass(), false);
   }
 
   Elemts.push_back(Tracer ? 
@@ -1245,7 +1241,7 @@
 
 #ifdef WITH_TRACER
 llvm::Function* JavaAOTCompiler::makeTracer(Class* cl, bool stat) {
-  if (!generateTracers || (!cl->super && !stat)) {
+  if (!generateTracers) {
     return JavaIntrinsics.JavaObjectTracerFunction;
   } else {
     return internalMakeTracer(cl, stat);
@@ -1451,19 +1447,13 @@
         JavaVirtualTable::getFirstJavaMethodIndex();
     memcpy(VT->getFirstJavaMethod(), cl->super->virtualVT->getFirstJavaMethod(),
            size * sizeof(uintptr_t));
-    VT->destructor = cl->super->virtualVT->destructor;
   }
   
   for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
     JavaMethod& meth = cl->virtualMethods[i];
     ((void**)VT)[meth.offset] = &meth;
   }
-
   if (!cl->super) VT->destructor = 0;
-
-  LLVMClassInfo* LCI = getClassInfo(cl);
-  if (!LCI->virtualTracerFunction) 
-    LCI->virtualTracerFunction = makeTracer(cl, false);
 }
 
 void JavaAOTCompiler::setMethod(JavaMethod* meth, void* ptr, const char* name) {
@@ -1477,15 +1467,16 @@
   Function* func = Function::Create(JnjvmModule::MarkAndTraceType,
                                     GlobalValue::ExternalLinkage,
                                     name, getLLVMModule());
-
+       
   LLVMClassInfo* LCI = getClassInfo(VT->cl->asClass());
   LCI->virtualTracerFunction = func;
 }
 
 void JavaAOTCompiler::setDestructor(JavaVirtualTable* VT, uintptr_t ptr,
                                     const char* name) {
-  // Set the name info into the operatorDelete directly, the compiler
-  // will use the name to create a LLVM function.
+  // Set the name info directly, the compiler will use the name to
+  // create a LLVM function.
+  VT->destructor = (uintptr_t)name;
   VT->operatorDelete = (uintptr_t)name;
 }
 
@@ -1664,7 +1655,7 @@
   mvm::BumpPtrAllocator A;
   Jnjvm* vm = new(A) Jnjvm(A, (JnjvmBootstrapLoader*)JCL);
   JavaThread* th = new JavaThread(0, 0, vm);
-  vm->setMainThread(th);
+  vm->setBootstrapThread(th);
   th->start((void (*)(mvm::Thread*))mainCompilerStart);
   vm->waitForExit();
 }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITCompiler.cpp Mon May  4 02:42:08 2009
@@ -136,14 +136,25 @@
 void JavaJITCompiler::makeVT(Class* cl) { 
   JavaVirtualTable* VT = cl->virtualVT; 
   assert(VT && "No VT was allocated!");
-    
-  LLVMClassInfo* LCI = getClassInfo(cl);
 
+#ifdef WITH_TRACER
   if (VT->init) {
+    // So the class is vmjc'ed. Create the virtual tracer.
+    Function* func = Function::Create(JnjvmModule::MarkAndTraceType,
+                                      GlobalValue::ExternalLinkage,
+                                      "markAndTraceObject",
+                                      getLLVMModule());
+       
+    uintptr_t ptr = VT->tracer;
+    JnjvmModule::executionEngine->addGlobalMapping(func, (void*)ptr);
+    LLVMClassInfo* LCI = getClassInfo(cl);
+    LCI->virtualTracerFunction = func;
+
     // The VT hash already been filled by the AOT compiler so there
     // is nothing left to do!
     return;
   }
+#endif
   
   if (cl->super) {
     // Copy the super VT into the current VT.
@@ -151,7 +162,6 @@
         JavaVirtualTable::getFirstJavaMethodIndex();
     memcpy(VT->getFirstJavaMethod(), cl->super->virtualVT->getFirstJavaMethod(),
            size * sizeof(uintptr_t));
-    VT->destructor = cl->super->virtualVT->destructor;
   }
 
 
@@ -165,11 +175,13 @@
     // 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)
       if (!cl->super) {
         meth.canBeInlined = true;
       } else {
         VT->destructor = (uintptr_t)EE->getPointerToFunctionOrStub(func);
       }
+#endif
     } else {
       VT->getFunctions()[meth.offset] = 
         (uintptr_t)EE->getPointerToFunctionOrStub(func);
@@ -177,29 +189,15 @@
   }
 
 #ifdef WITH_TRACER
-  if (!LCI->virtualTracerFunction) {
-    LCI->virtualTracerFunction = makeTracer(cl, false);
-  }
+  Function* func = makeTracer(cl, false);
+  
+  void* codePtr = mvm::MvmModule::executionEngine->getPointerToFunction(func);
+  VT->tracer = (uintptr_t)codePtr;
+  func->deleteBody();
 #endif
     
 }
 
-Function* JavaJITCompiler::makeTracer(Class* cl, bool stat) {
-  Function* F = cl->super || stat ?
-    internalMakeTracer(cl, stat) : JavaIntrinsics.JavaObjectTracerFunction;
- 
-  assert(F && "No tracer");
-  if (stat) {
-    cl->staticTracer = (void (*)(void*)) (uintptr_t)
-      JnjvmModule::executionEngine->getPointerToFunction(F);
-  } else {
-    void* codePtr = mvm::MvmModule::executionEngine->getPointerToFunction(F);
-    cl->virtualVT->tracer = (uintptr_t)codePtr;
-  }
-  F->deleteBody();
-  return F;
-}
-
 void JavaJITCompiler::setMethod(JavaMethod* meth, void* ptr, const char* name) {
   Function* func = getMethodInfo(meth)->getMethod();
   func->setName(name);
@@ -220,22 +218,19 @@
   JnjvmModule::executionEngine->addGlobalMapping(func, (void*)ptr);
   LLVMClassInfo* LCI = getClassInfo(VT->cl->asClass());
   LCI->virtualTracerFunction = func;
-  VT->tracer = ptr;
 }
 
 void JavaJITCompiler::setDestructor(JavaVirtualTable* VT, uintptr_t ptr,
                                     const char* name) {
-  VT->destructor = ptr;
-  VT->operatorDelete = ptr;
+  // Nothing to do: the virtual table has already set its destructor
+  // and no one uses the destructor as a LLVM function.
 }
 
 void* JavaJITCompiler::materializeFunction(JavaMethod* meth) {
   Function* func = parseFunction(meth);
   
   void* res = mvm::MvmModule::executionEngine->getPointerToGlobal(func);
-  mvm::MvmModule::protectIR();
   func->deleteBody();
-  mvm::MvmModule::unprotectIR();
 
   return res;
 }
@@ -245,6 +240,7 @@
   llvm::llvm_shutdown_obj X;  
    
   mvm::MvmModule::initialise();
+  mvm::Object::initialise();
   Collector::initialise(0);
  
   char** newArgv = new char*[argc + 1];

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JnjvmModule.cpp Mon May  4 02:42:08 2009
@@ -105,19 +105,6 @@
     nbFields = cl->nbVirtualFields;
   }
   
-  uint32 nbReferenceFields = 0;
-  for (uint32 i = 0; i < nbFields; ++i) {
-    JavaField& cur = fields[i];
-    if (cur.getSignature()->trace()) {
-      ++nbReferenceFields;
-    }
-  }
-
-  if (!nbReferenceFields) {
-    if (stat) return JavaIntrinsics.EmptyTracerFunction;
-    else return getClassInfo(cl->super)->getVirtualTracer();
-  }
-  
   Function* func = Function::Create(JnjvmModule::MarkAndTraceType,
                                     GlobalValue::InternalLinkage,
                                     "", getLLVMModule());
@@ -139,9 +126,16 @@
                        Args.end(), "", block);
 
     } else {
-      LLVMClassInfo* LCP = getClassInfo(cl->super);
-      Function* F = LCP->getVirtualTracer();
-      assert(F && "Still no virtual tracer for super");
+      LLVMClassInfo* LCP = (LLVMClassInfo*)getClassInfo((Class*)(cl->super));
+      Function* F = LCP->virtualTracerFunction;
+      if (!F) {
+        if (isStaticCompiling()) {
+          F = internalMakeTracer(cl->super, false);
+        } else {
+          F = LCP->getVirtualTracer();
+        }
+        assert(F && "Still no virtual tracer for super");
+      }
       CallInst::Create(F, Args.begin(), Args.end(), "", block);
     }
   }
@@ -170,6 +164,12 @@
 
   ReturnInst::Create(block);
   
+  if (!stat) {
+    LCI->virtualTracerFunction = func;
+  } else {
+    LCI->staticTracerFunction = func;
+  }
+
   return func;
 }
 #endif
@@ -418,7 +418,6 @@
 #ifdef WITH_TRACER
   MarkAndTraceFunction = module->getFunction("MarkAndTrace");
   JavaObjectTracerFunction = module->getFunction("JavaObjectTracer");
-  EmptyTracerFunction = module->getFunction("EmptyTracer");
   JavaArrayTracerFunction = module->getFunction("JavaArrayTracer");
   ArrayObjectTracerFunction = module->getFunction("ArrayObjectTracer");
 #endif

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.cpp Mon May  4 02:42:08 2009
@@ -361,10 +361,13 @@
 }
 
 void JavaVirtualTable::setNativeTracer(uintptr_t ptr, const char* name) {
+  tracer = ptr;
   cl->classLoader->getCompiler()->setTracer(this, ptr, name);
 }
 
 void JavaVirtualTable::setNativeDestructor(uintptr_t ptr, const char* name) {
+  destructor = ptr;
+  operatorDelete = ptr;
   cl->classLoader->getCompiler()->setDestructor(this, ptr, name);
 }
 
@@ -570,7 +573,9 @@
 }
 
 bool JavaVirtualTable::isSubtypeOf(JavaVirtualTable* otherVT) {
-  
+ 
+  assert(this);
+  assert(otherVT);
   if (otherVT == ((JavaVirtualTable**)this)[otherVT->offset]) return true;
   else if (otherVT->offset != getCacheIndex()) return false;
   else if (this == otherVT) return true;
@@ -694,9 +699,6 @@
   if (superEntry) {
     const UTF8* superUTF8 = ctpInfo->resolveClassName(superEntry);
     super = classLoader->loadName(superUTF8, false, true);
-    virtualTableSize = super->virtualTableSize;
-  } else {
-    virtualTableSize = JavaVirtualTable::getFirstJavaMethodIndex();
   }
 
   uint16 nbI = reader.readU2();
@@ -715,11 +717,15 @@
 }
 
 void UserClass::loadParents() {
-  if (super)
+  if (super == 0) {
+    virtualTableSize = JavaVirtualTable::getFirstJavaMethodIndex();
+  } else  {
     super->resolveClass();
+    virtualTableSize = super->virtualTableSize;
+  }
 
   for (unsigned i = 0; i < nbInterfaces; i++)
-    interfaces[i]->resolveClass();
+    interfaces[i]->resolveClass(); 
 }
 
 
@@ -747,9 +753,7 @@
       reader.readU2();
 
       uint16 catche = reader.readU2();
-      if (catche) {
-        meth.classDef->ctpInfo->loadClass(catche, false);
-      }
+      if (catche) meth.classDef->ctpInfo->loadClass(catche);
     }
   }
 }
@@ -808,8 +812,7 @@
   
   for (uint32 i = 0; i < nbVirtualMethods; ++i) {
     JavaMethod& meth = virtualMethods[i];
-    if (meth.name->equals(classLoader->bootstrapLoader->finalize) &&
-        meth.type->equals(classLoader->bootstrapLoader->clinitType)) {
+    if (meth.name->equals(classLoader->bootstrapLoader->finalize)) {
       meth.offset = 0;
     } else {
       JavaMethod* parent = super? 
@@ -892,7 +895,6 @@
   readParents(reader);
   readFields(reader);
   readMethods(reader);
-  makeVT();
   attributs = readAttributs(reader, nbAttributs);
   setIsRead();
 }
@@ -905,14 +907,19 @@
       release();
     } else if (!isResolving()) {
       setOwnerClass(JavaThread::get());
-      setIsResolving();
+      readClass();
       release();
-
+      
       loadParents();
+      makeVT();
       JavaCompiler *Comp = classLoader->getCompiler();
       Comp->resolveVirtualClass(this);
       Comp->resolveStaticClass(this);
       loadExceptions();
+      setResolved();
+      if (!needsInitialisationCheck()) {
+        setInitializationState(ready);
+      }
       if (!super) ClassArray::initialiseVT(this);
       
       bool needInit = needsInitialisationCheck();
@@ -947,12 +954,11 @@
       for (uint16 i = 0; i < nbi; ++i) {
         uint16 inner = reader.readU2();
         uint16 outer = reader.readU2();
-        uint16 innerName = reader.readU2();
+        //uint16 innerName = 
+        reader.readU2();
         uint16 accessFlags = reader.readU2();
-        UserClass* clInner = 0;
-        UserClass* clOuter = 0;
-        if (inner) clInner = (UserClass*)ctpInfo->loadClass(inner);
-        if (outer) clOuter = (UserClass*)ctpInfo->loadClass(outer);
+        UserClass* clInner = (UserClass*)ctpInfo->loadClass(inner);
+        UserClass* clOuter = (UserClass*)ctpInfo->loadClass(outer);
 
         if (clInner == this) {
           outerClass = clOuter;
@@ -962,7 +968,6 @@
               classLoader->allocator.Allocate(nbi * sizeof(Class*));
           }
           clInner->setInnerAccess(accessFlags);
-          if (!innerName) isAnonymous = true;
           innerClasses[nbInnerClasses++] = clInner;
         }
       }
@@ -1208,7 +1213,7 @@
 
 bool UserClass::needsInitialisationCheck() {
   
-  if (!isResolved()) return true;
+  if (!isClassRead()) return true;
 
   if (isReady()) return false;
 
@@ -1305,12 +1310,8 @@
       offset = getCacheIndex() + depth + 1;
     } else {
       offset = getCacheIndex();
-      // Add the super in the list of secondary types only if it is
-      // out of depth.
-      if (depth > getDisplayLength()) {
-        ++nbSecondaryTypes;
-        outOfDepth = 1;
-      }
+      ++nbSecondaryTypes;
+      outOfDepth = 1;
     }
 
     mvm::BumpPtrAllocator& allocator = C->classLoader->allocator;
@@ -1366,10 +1367,12 @@
   
 JavaVirtualTable::JavaVirtualTable(ClassArray* C) {
   
-  baseClassVT = C->baseClass()->virtualVT;
-  assert(baseClassVT && "Not base VT when creating an array");
+  if (C->baseClass()->isClass())
+    C->baseClass()->asClass()->resolveClass();
 
   if (!C->baseClass()->isPrimitive()) {
+    baseClassVT = C->baseClass()->virtualVT;
+
     // Copy the super VT into the current VT.
     uint32 size = (getBaseSize() - getFirstJavaMethodIndex());
     memcpy(this->getFirstJavaMethod(),
@@ -1385,45 +1388,29 @@
     Classpath* upcalls = JCL->bootstrapLoader->upcalls;
     
     if (upcalls->ArrayOfObject) {
-      UserCommonClass* base = C->baseClass();
+      UserCommonClass* temp = C->baseClass();
       uint32 dim = 1;
-      while (base->isArray()) {
-        base = base->asArrayClass()->baseClass();
+      while (temp->isArray()) {
+        temp = temp->asArrayClass()->baseClass();
         ++dim;
       }
      
       bool newSecondaryTypes = false;
-      bool intf = base->isInterface();
-      const UTF8* superName = 0;
-
-      if (base->isPrimitive()) {
-        // If the base class is primitive, then the super is one
-        // dimension below, e.g. the super of int[][] is Object[].
+      bool intf = temp->isInterface();
+      if (temp->isPrimitive()) {
         --dim;
-        superName = JCL->constructArrayName(dim, C->super->name);
-      } else if (base == C->super) {
-        // If the base class is java.lang.Object, then the super is one
-        // dimension below, e.g. the super of Object[][] is Object[].
-        // Also, the class is the first class in the dimension hierarchy,
-        // so it must create a new secondary type list.
+        temp = C->super;
+      } else if (temp == C->super) {
         --dim;
         newSecondaryTypes = true;
-        superName = JCL->constructArrayName(dim, C->super->name);
       } else {
-        // If the base class is any other class, interface or not,
-        // the super is of the dimension of the current array class,
-        // and whose base class is the super of this base class.
-        superName = JCL->constructArrayName(dim, base->super->name);
+        temp = temp->super;
       }
-     
-      // Construct the super array class, e.g. java.lang.Object[] for
-      // java.lang.Class[].
-      ClassArray* super = JCL->constructArray(superName);
+      
+      const UTF8* name = JCL->constructArrayName(dim, temp->name);
+      ClassArray* super = JCL->constructArray(name);
       JavaVirtualTable* superVT = super->virtualVT;
       depth = superVT->depth + 1;
-      
-      // Record if we need to add the super in the list of secondary types.
-      uint32 addSuper = 0;
 
       uint32 length = getDisplayLength() < depth ? getDisplayLength() : depth;
       memcpy(display, superVT->display, length * sizeof(JavaVirtualTable*)); 
@@ -1432,51 +1419,27 @@
         offset = getCacheIndex() + depth + 1;
       } else {
         offset = getCacheIndex();
-        // We add the super if the current class is an interface or if the super
-        // class is out of depth.
-        if (intf || depth != getDisplayLength()) addSuper = 1;
       }
         
       mvm::BumpPtrAllocator& allocator = JCL->allocator;
 
       if (!newSecondaryTypes) {
-        if (base->nbInterfaces || addSuper) {
-          // If the base class implements interfaces, we must also add the
-          // arrays of these interfaces, of the same dimension than this array
-          // class and add them to the secondary types list.
-          nbSecondaryTypes = base->nbInterfaces + superVT->nbSecondaryTypes +
-                                addSuper;
+        if (depth < getDisplayLength()) {
+          nbSecondaryTypes = superVT->nbSecondaryTypes;
+          secondaryTypes = superVT->secondaryTypes;
+        } else {
+          nbSecondaryTypes = superVT->nbSecondaryTypes + 1;
           secondaryTypes = (JavaVirtualTable**)
             allocator.Allocate(sizeof(JavaVirtualTable*) * nbSecondaryTypes);
-         
-          // Put the super in the list of secondary types.
-          if (addSuper) secondaryTypes[0] = superVT;
-
-          // Copy the list of secondary types of the super.
-          memcpy(secondaryTypes + addSuper, superVT->secondaryTypes,
+          secondaryTypes[0] = this;
+          memcpy(secondaryTypes + 1 , superVT->secondaryTypes,
                  superVT->nbSecondaryTypes * sizeof(JavaVirtualTable*));
-        
-          // Add our own secondary types: the interfaces of the base class put
-          // in the dimension of the current array class.
-          for (uint32 i = 0; i < base->nbInterfaces; ++i) {
-            const UTF8* name = 
-              JCL->constructArrayName(dim, base->interfaces[i]->name);
-            ClassArray* interface = JCL->constructArray(name);
-            JavaVirtualTable* CurVT = interface->virtualVT;
-            secondaryTypes[i + superVT->nbSecondaryTypes + addSuper] = CurVT;
-          }
-        } else {
-          // If the super is not a secondary type and the base class does not
-          // implement any interface, we can reuse the list of secondary types
-          // of super.
-          nbSecondaryTypes = superVT->nbSecondaryTypes;
-          secondaryTypes = superVT->secondaryTypes;
         }
       } else {
 
         // This is an Object[....] array class. It will create the list of
-        // secondary types and all array classes of the same dimension whose
-        // base class does not have interfaces point to this array.
+        // secondary types and all array classes of the same dimension will
+        // point to this array.
 
         // If we're superior than the display limit, we must make room for one
         // slot that will contain the current VT.

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Mon May  4 02:42:08 2009
@@ -50,12 +50,11 @@
 ///
 #define loaded 0       /// The .class file has been found.
 #define classRead 1    /// The .class file has been read.
-#define resolving 2    /// The class file is being resolved.
-#define resolved 3     /// The class has been resolved.
-#define vmjc 4         /// The class is defined in a shared library.
-#define inClinit 5     /// The class is cliniting.
-#define ready 6        /// The class is ready to be used.
-#define erroneous 7    /// The class is in an erroneous state.
+#define resolved 2     /// The class has been resolved.
+#define vmjc 3         /// The class is defined in a shared library.
+#define inClinit 4     /// The class is cliniting.
+#define ready 5        /// The class is ready to be used.
+#define erroneous 6    /// The class is in an erroneous state.
 
 /// JavaVirtualTable - This class is the virtual table of instances of
 /// Java classes. Besides holding function pointers for virtual calls,
@@ -672,10 +671,6 @@
   ///
   bool innerOuterResolved;
   
-  /// isAnonymous - Is the class an anonymous class?
-  ///
-  bool isAnonymous;
-
   /// virtualTableSize - The size of the virtual table of this class.
   ///
   uint32 virtualTableSize;
@@ -926,12 +921,6 @@
     getCurrentTaskClassMirror().status = classRead;
   }
   
-  /// setIsResolving - The class file is being resolved.
-  ///
-  void setIsResolving() {
-    getCurrentTaskClassMirror().status = resolving;
-  }
-  
 
 #else
   
@@ -953,12 +942,6 @@
     }
   }
   
-  void setIsResolving() {
-    for (uint32 i = 0; i < NR_ISOLATES; ++i) {
-      IsolateInfo[i].status = resolving;
-    }
-  }
-  
   void setErroneous() {
     for (uint32 i = 0; i < NR_ISOLATES; ++i) {
       IsolateInfo[i].status = erroneous;
@@ -1020,7 +1003,7 @@
   /// isResolving - Is the class currently being resolved?
   ///
   bool isResolving() {
-    return getCurrentTaskClassMirror().status == resolving;
+    return getCurrentTaskClassMirror().status == classRead;
   }
 
   /// isClassRead - Has the .class file been read?

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaInitialise.cpp Mon May  4 02:42:08 2009
@@ -23,8 +23,29 @@
 using namespace jnjvm;
 
 
+static void initialiseVT() {
+
+# define INIT(X) { \
+  X fake; \
+  X::VT = ((VirtualTable**)(void*)(&fake))[0]; }
+
+  INIT(LockObj);
+  INIT(VMClassLoader);
+
+#ifdef ISOLATE_SHARING
+  INIT(JnjvmSharedLoader);
+  INIT(SharedClassByteMap);
+  INIT(UserClass);
+  INIT(UserClassArray);
+  INIT(UserConstantPool);
+#endif
+#undef INIT
+
+}
+
 #ifdef ISOLATE_SHARING
 JnjvmClassLoader* mvm::VirtualMachine::initialiseJVM(JavaCompiler* Comp) {
+  initialiseVT();
   JnjvmSharedLoader::sharedLoader = JnjvmSharedLoader::createSharedLoader(Comp);
   return JnjvmSharedLoader::sharedLoader;
 }
@@ -41,6 +62,7 @@
   
 JnjvmClassLoader*
 mvm::VirtualMachine::initialiseJVM(JavaCompiler* Comp, bool dlLoad) {
+  initialiseVT();
   mvm::BumpPtrAllocator* A = new mvm::BumpPtrAllocator();
   return new(*A) JnjvmBootstrapLoader(*A, Comp, dlLoad);
 }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaMetaJIT.cpp Mon May  4 02:42:08 2009
@@ -15,7 +15,6 @@
 #include "JavaObject.h"
 #include "JavaThread.h"
 #include "JavaTypes.h"
-#include "JavaUpcalls.h"
 #include "Jnjvm.h"
 
 using namespace jnjvm;
@@ -625,18 +624,3 @@
 INVOKE(JavaObject*, JavaObject, object_virtual_ap, object_static_ap, object_virtual_buf, object_static_buf)
 
 #undef INVOKE
-
-
-void Jnjvm::invokeFinalizer(gc* _obj) {
-  JavaObject* obj = (JavaObject*)_obj;
-  JavaMethod* meth = upcalls->FinalizeObject;
-  UserClass* cl = obj->getClass()->asClass();
-  meth->invokeIntVirtualBuf(this, cl, obj, 0);
-}
-
-bool Jnjvm::enqueueReference(gc* _obj) {
-  JavaObject* obj = (JavaObject*)_obj;
-  JavaMethod* meth = upcalls->EnqueueReference;
-  UserClass* cl = obj->getClass()->asClass();
-  return (bool)meth->invokeIntSpecialBuf(this, cl, obj, 0);
-}

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp Mon May  4 02:42:08 2009
@@ -70,12 +70,7 @@
 #ifdef USE_GC_BOEHM
   LockObj* res = new LockObj();
 #else
-  LockObj* res = new(&VT) LockObj();
-  // Set the virtual table to change what C++ did: by using the new operator
-  // C++ after the allocation will set its own VT. Since we want to call
-  // the C++ constructor (because it initializes the native data structures
-  // such as LockRecursive), we have to change the VT of this object.
-  res->setVirtualTable(&VT);
+  LockObj* res = gc_new(LockObj)();
 #endif
   return res;
 }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h Mon May  4 02:42:08 2009
@@ -107,7 +107,7 @@
 
   /// VT - LockObj is GC-allocated, so we must make the VT explicit.
   ///
-  static VirtualTable VT;
+  static VirtualTable* VT;
 
   ~LockObj() {}
   LockObj() {}

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaString.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaString.cpp Mon May  4 02:42:08 2009
@@ -28,10 +28,6 @@
   // internStringVT exists (in case of AOT).
   if (internStringVT) res->setVirtualTable(internStringVT);
 
-  // The GC did not have this info. Now we do, so inform the finalizers
-  // that this is a finalization candidate.
-  vm->addFinalizationCandidate(res);
-
   // No need to call the Java function: both the Java function and
   // this function do the same thing.
   res->value = utf8;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.cpp Mon May  4 02:42:08 2009
@@ -18,12 +18,12 @@
 
 #define COMPILE_METHODS(cl) \
   for (CommonClass::method_iterator i = cl->virtualMethods.begin(), \
-            e = cl->virtualMethods.end(); i!= e; ++i) { \
+            e = cl->virtualMethods.end(); i!= e; +i) { \
     i->second->compiledPtr(); \
   } \
   \
   for (CommonClass::method_iterator i = cl->staticMethods.begin(), \
-            e = cl->staticMethods.end(); i!= e; ++i) { \
+            e = cl->staticMethods.end(); i!= e; +i) { \
     i->second->compiledPtr(); \
   }
 
@@ -38,9 +38,7 @@
 JavaMethod* Classpath::finaliseCreateInitialThread;
 JavaMethod* Classpath::initVMThread;
 JavaMethod* Classpath::groupAddThread;
-JavaMethod* Classpath::initGroup;
-JavaField*  Classpath::groupName;
-JavaField*  Classpath::threadName;
+JavaField*  Classpath::name;
 JavaField*  Classpath::priority;
 JavaField*  Classpath::daemon;
 JavaField*  Classpath::group;
@@ -177,7 +175,6 @@
 JavaMethod* Classpath::InitClassNotFoundException;
 JavaMethod* Classpath::InitArithmeticException;
 JavaMethod* Classpath::InitObject;
-JavaMethod* Classpath::FinalizeObject;
 
 JavaMethod* Classpath::ErrorWithExcpNoClassDefFoundError;
 JavaMethod* Classpath::ErrorWithExcpExceptionInInitializerError;
@@ -208,9 +205,6 @@
 JavaField* Classpath::fieldClass;
 JavaField* Classpath::constructorClass;
 
-JavaMethod* Classpath::EnqueueReference;
-Class*      Classpath::newReference;
-
 #endif
 
 void Classpath::CreateJavaThread(Jnjvm* vm, JavaThread* myth,
@@ -220,7 +214,7 @@
   myth->javaThread = th;
   JavaObject* vmth = newVMThread->doNew(vm);
   
-  threadName->setObjectField(th, (JavaObject*)vm->asciizToStr(thName));
+  name->setObjectField(th, (JavaObject*)vm->asciizToStr(thName));
   priority->setInt32Field(th, (uint32)1);
   daemon->setInt8Field(th, (uint32)0);
   vmThread->setObjectField(th, vmth);
@@ -245,22 +239,11 @@
   threadGroup->resolveClass();
   threadGroup->initialiseClass(vm);
 
-  // Create the main thread.
+  // Create the main thread
   void* Stat = threadGroup->getStaticInstance();
   JavaObject* RG = rootGroup->getObjectField(Stat);
-  assert(vm->getMainThread() && "VM did not set its bootstrap thread");
-  CreateJavaThread(vm, vm->getMainThread(), "main", RG);
-
-  // Create the "system" group.
-  JavaObject* SystemGroup = threadGroup->doNew(vm);
-  initGroup->invokeIntSpecial(vm, threadGroup, SystemGroup);
-  JavaObject* systemName = (JavaObject*)vm->asciizToStr("system");
-  groupName->setObjectField(SystemGroup, systemName);
-
-  // And create the finalizer thread.
-  assert(vm->getFinalizerThread() && "VM did not set its finalizer thread");
-  CreateJavaThread(vm, vm->getFinalizerThread(), "Finalizer", SystemGroup);
-
+  assert(vm->getBootstrapThread() && "VM did not set its bootstrap thread");
+  CreateJavaThread(vm, vm->getBootstrapThread(), "main", RG);
 }
 
 extern "C" JavaString* nativeInternString(JavaString* obj) {
@@ -339,44 +322,6 @@
 extern "C" void nativePropertiesPostInit(JavaObject* prop);
 
 
-extern "C" void nativeInitWeakReference(JavaObjectReference* reference,
-                                        JavaObject* referent) {
-  reference->init(referent, 0);
-  JavaThread::get()->getJVM()->addWeakReference(reference);
-
-}
-
-extern "C" void nativeInitWeakReferenceQ(JavaObjectReference* reference,
-                                         JavaObject* referent,
-                                         JavaObject* queue) {
-  reference->init(referent, queue);
-  JavaThread::get()->getJVM()->addWeakReference(reference);
-
-}
-
-extern "C" void nativeInitSoftReference(JavaObjectReference* reference,
-                                        JavaObject* referent) {
-  reference->init(referent, 0);
-  JavaThread::get()->getJVM()->addSoftReference(reference);
-
-}
-
-extern "C" void nativeInitSoftReferenceQ(JavaObjectReference* reference,
-                                         JavaObject* referent,
-                                         JavaObject* queue) {
-  reference->init(referent, queue);
-  JavaThread::get()->getJVM()->addSoftReference(reference);
-
-}
-
-extern "C" void nativeInitPhantomReferenceQ(JavaObjectReference* reference,
-                                            JavaObject* referent,
-                                            JavaObject* queue) {
-  reference->init(referent, queue);
-  JavaThread::get()->getJVM()->addPhantomReference(reference);
-
-}
-
 extern "C" void nativeJavaObjectClassTracer(JavaObjectClass* obj) {
   JavaObjectClass::staticTracer(obj);
 }
@@ -393,10 +338,6 @@
   JavaObjectConstructor::staticTracer(obj);
 }
 
-extern "C" void nativeJavaObjectReferenceTracer(JavaObjectReference* obj) {
-  JavaObjectReference::staticTracer(obj);
-}
-
 extern "C" void nativeJavaObjectVMThreadDestructor(JavaObjectVMThread* obj) {
   JavaObjectVMThread::staticDestructor(obj);
 }
@@ -664,9 +605,6 @@
 
   InitObject = UPCALL_METHOD(loader, "java/lang/Object", "<init>", "()V",
                              ACC_VIRTUAL);
-  
-  FinalizeObject = UPCALL_METHOD(loader, "java/lang/Object", "finalize", "()V",
-                                 ACC_VIRTUAL);
 
   newThread = 
     UPCALL_CLASS(loader, "java/lang/Thread");
@@ -701,15 +639,7 @@
     UPCALL_METHOD(loader, "java/lang/ThreadGroup", "addThread",
                   "(Ljava/lang/Thread;)V", ACC_VIRTUAL);
   
-  initGroup = 
-    UPCALL_METHOD(loader, "java/lang/ThreadGroup", "<init>",
-                  "()V", ACC_VIRTUAL);
-  
-  groupName = 
-    UPCALL_FIELD(loader, "java/lang/ThreadGroup", "name", "Ljava/lang/String;",
-                 ACC_VIRTUAL);
-  
-  threadName = 
+  name = 
     UPCALL_FIELD(loader, "java/lang/Thread", "name", "Ljava/lang/String;",
                  ACC_VIRTUAL);
   
@@ -810,104 +740,33 @@
                   ACC_VIRTUAL);
   getAnnotations->setCompiledPtr((void*)(intptr_t)nativeGetDeclaredAnnotations,
                                  "nativeGetDeclaredAnnotations");
-
-//===----------------------------------------------------------------------===//
-//
-// Weak/Soft/Phantom references support. We modify each constructor to register
-// the reference to the VM. Also, the tracer of the Reference class is modified
-// to not trace the referent.
-//
-//===----------------------------------------------------------------------===//
-
- 
-  newReference =
-    loader->loadName(loader->asciizConstructUTF8("java/lang/ref/Reference"),
-                     false, false);
-  
-  newReference->getVirtualVT()->setNativeTracer(
-      (uintptr_t)nativeJavaObjectReferenceTracer,
-      "nativeJavaObjectReferenceTracer");
   
-  assert(!newReference->isResolved() && "Reference class already resolved");
-  
-  EnqueueReference = 
-    UPCALL_METHOD(loader, "java/lang/ref/Reference",  "enqueue", "()Z",
-                  ACC_VIRTUAL);
- 
-  JavaMethod* initWeakReference =
-    UPCALL_METHOD(loader, "java/lang/ref/WeakReference", "<init>",
-                  "(Ljava/lang/Object;)V",
-                  ACC_VIRTUAL);
-  initWeakReference->setCompiledPtr((void*)(intptr_t)nativeInitWeakReference,
-                                    "nativeInitWeakReference");
-  
-  initWeakReference =
-    UPCALL_METHOD(loader, "java/lang/ref/WeakReference", "<init>",
-                  "(Ljava/lang/Object;Ljava/lang/ref/ReferenceQueue;)V",
-                  ACC_VIRTUAL);
-  initWeakReference->setCompiledPtr((void*)(intptr_t)nativeInitWeakReferenceQ,
-                                    "nativeInitWeakReferenceQ");
-  
-  JavaMethod* initSoftReference =
-    UPCALL_METHOD(loader, "java/lang/ref/SoftReference", "<init>",
-                  "(Ljava/lang/Object;)V",
-                  ACC_VIRTUAL);
-  initSoftReference->setCompiledPtr((void*)(intptr_t)nativeInitSoftReference,
-                                    "nativeInitSoftReference");
-  
-  initSoftReference =
-    UPCALL_METHOD(loader, "java/lang/ref/WeakReference", "<init>",
-                  "(Ljava/lang/Object;Ljava/lang/ref/ReferenceQueue;)V",
-                  ACC_VIRTUAL);
-  initSoftReference->setCompiledPtr((void*)(intptr_t)nativeInitSoftReferenceQ,
-                                    "nativeInitSoftReferenceQ");
-  
-  JavaMethod* initPhantomReference =
-    UPCALL_METHOD(loader, "java/lang/ref/PhantomReference", "<init>",
-                  "(Ljava/lang/Object;Ljava/lang/ref/ReferenceQueue;)V",
-                  ACC_VIRTUAL);
-  initPhantomReference->setCompiledPtr(
-      (void*)(intptr_t)nativeInitPhantomReferenceQ,
-      "nativeInitPhantomReferenceQ");
-  
-
-//===----------------------------------------------------------------------===//
-//
-// To make classes non GC-allocated, we have to bypass the tracer functions of
-// java.lang.Class, java.lang.reflect.Field, java.lang.reflect.Method and
-// java.lang.reflect.constructor. The new tracer functions trace the classloader
-// instead of the class/field/method.
-//
-//===----------------------------------------------------------------------===//
+  //===----------------------------------------------------------------------===//
+  //
+  // To make classes non GC-allocated, we have to bypass the tracer functions of
+  // java.lang.Class, java.lang.reflect.Field, java.lang.reflect.Method and
+  // java.lang.reflect.constructor. The new tracer functions trace the classloader
+  // instead of the class/field/method.
+  //
+  //===----------------------------------------------------------------------===//
  
   newClass->getVirtualVT()->setNativeTracer(
       (uintptr_t)nativeJavaObjectClassTracer,
-      "nativeJavaObjectClassTracer");
-  
+       "nativeJavaObjectClassTracer");
+
   newConstructor->getVirtualVT()->setNativeTracer(
       (uintptr_t)nativeJavaObjectConstructorTracer,
       "nativeJavaObjectConstructorTracer");
-  
-  newMethod->getVirtualVT()->setNativeTracer(
+
+   newMethod->getVirtualVT()->setNativeTracer(
       (uintptr_t)nativeJavaObjectMethodTracer,
       "nativeJavaObjectMethodTracer");
-  
-  newField->getVirtualVT()->setNativeTracer(
-      (uintptr_t)nativeJavaObjectFieldTracer,
-      "nativeJavaObjectFieldTracer");
-  
 
-  newVMThread->getVirtualVT()->setNativeDestructor(
+   newField->getVirtualVT()->setNativeTracer(
+      (uintptr_t)nativeJavaObjectFieldTracer,
+      "nativeJavaObjectFieldTracer"); 
+ 
+   newVMThread->getVirtualVT()->setNativeDestructor(
       (uintptr_t)nativeJavaObjectVMThreadDestructor,
-      "nativeJavaObjectVMThreadDestructor");
-}
-
-gc* Jnjvm::getReferent(gc* _obj) {
-  JavaObjectReference* obj = (JavaObjectReference*)_obj;
-  return obj->getReferent();
-}
-
-void Jnjvm::clearReferent(gc* _obj) {
-  JavaObjectReference* obj = (JavaObjectReference*)_obj;
-  obj->setReferent(0);
+      "nativeJavaObjectVMThreadDestructorr");
 }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaUpcalls.h Mon May  4 02:42:08 2009
@@ -131,9 +131,7 @@
   ISOLATE_STATIC JavaMethod* initVMThread;
   ISOLATE_STATIC JavaMethod* runVMThread;
   ISOLATE_STATIC JavaMethod* groupAddThread;
-  ISOLATE_STATIC JavaMethod* initGroup;
-  ISOLATE_STATIC JavaField* groupName;
-  ISOLATE_STATIC JavaField* threadName;
+  ISOLATE_STATIC JavaField* name;
   ISOLATE_STATIC JavaField* priority;
   ISOLATE_STATIC JavaField* daemon;
   ISOLATE_STATIC JavaField* group;
@@ -210,7 +208,6 @@
   ISOLATE_STATIC JavaMethod* InitArithmeticException;
 
   ISOLATE_STATIC JavaMethod* InitObject;
-  ISOLATE_STATIC JavaMethod* FinalizeObject;
 
   ISOLATE_STATIC JavaMethod* ErrorWithExcpNoClassDefFoundError;
   ISOLATE_STATIC JavaMethod* ErrorWithExcpExceptionInInitializerError;
@@ -242,9 +239,6 @@
   ISOLATE_STATIC JavaField* methodClass;
   ISOLATE_STATIC JavaField* fieldClass;
   ISOLATE_STATIC JavaField* constructorClass;
-
-  ISOLATE_STATIC JavaMethod* EnqueueReference;
-  ISOLATE_STATIC Class*      newReference;
   
 private:
   ISOLATE_STATIC void CreateJavaThread(Jnjvm* vm, JavaThread* myth,

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Mon May  4 02:42:08 2009
@@ -814,13 +814,9 @@
     
     JavaString::internStringVT->destructor = 
       (uintptr_t)JavaString::stringDestructor;
-    
-    // Tell the finalizer that this is a native destructor.
-    JavaString::internStringVT->operatorDelete = 
-      (uintptr_t)JavaString::stringDestructor;
   }
   upcalls->newString->initialiseClass(this);
- 
+
 #ifdef SERVICE
   if (!IsolateID)
 #endif
@@ -965,7 +961,7 @@
 
 void Jnjvm::mainJavaStart(JavaThread* thread) {
   Jnjvm* vm = thread->getJVM();
-  vm->mainThread = thread;
+  vm->bootstrapThread = thread;
 
   vm->loadBootstrap();
 
@@ -1046,11 +1042,8 @@
     th->start(serviceCPUMonitor);
 #endif
     
-    finalizerThread = new JavaThread(0, 0, this);
-    finalizerThread->start((void (*)(mvm::Thread*))finalizerStart);
-    
-    mainThread = new JavaThread(0, 0, this);
-    mainThread->start((void (*)(mvm::Thread*))mainJavaStart);
+    bootstrapThread = new JavaThread(0, 0, this);
+    bootstrapThread->start((void (*)(mvm::Thread*))mainJavaStart);
   } else {
     threadSystem.nonDaemonThreads = 0;
   }
@@ -1143,6 +1136,7 @@
 
 // Helper function to run Jnjvm without JIT.
 extern "C" int StartJnjvmWithoutJIT(int argc, char** argv, char* mainClass) {
+  mvm::Object::initialise();
   Collector::initialise(0);
   
   char** newArgv = new char*[argc + 1];

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Mon May  4 02:42:08 2009
@@ -113,14 +113,10 @@
 
 private:
   
-  /// mainThread - The initial thread of this JVM.
+  /// bootstrapThread - The initial thread of this JVM.
   ///
-  JavaThread* mainThread;
+  JavaThread* bootstrapThread;
   
-  /// finalizerThread - The initial thread of this JVM.
-  ///
-  JavaThread* finalizerThread;
-   
   /// CreateError - Creates a Java object of the specified exception class
   /// and calling its <init> function.
   ///
@@ -305,19 +301,11 @@
   
   /// setBootstrapThread - Set the bootstrap thread of this VM.
   ///
-  void setMainThread(JavaThread* th) { mainThread = th; }
+  void setBootstrapThread(JavaThread* th) { bootstrapThread = th; }
   
   /// getBootstrapThread - Get the bootstrap thread of this VM.
   ///
-  JavaThread* getMainThread() const { return mainThread; }
-  
-  /// setFinalizerThread - Set the first finalizer thread of this VM.
-  ///
-  void setFinalizerThread(JavaThread* th) { finalizerThread = th; }
-  
-  /// getFinalizerThread - Get the finalizer thread of this VM.
-  ///
-  JavaThread* getFinalizerThread() const { return finalizerThread; }
+  JavaThread* getBootstrapThread() const { return bootstrapThread; }
 
   /// ~Jnjvm - Destroy the JVM.
   ///
@@ -360,13 +348,6 @@
   virtual void stopService();
 #endif
 
-protected:
-  virtual void invokeFinalizer(gc*);
-
-public:
-  virtual void clearReferent(gc*);
-  virtual gc* getReferent(gc*);
-  virtual bool enqueueReference(gc*);
 
 };
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.cpp Mon May  4 02:42:08 2009
@@ -564,7 +564,6 @@
   JnjvmClassLoader* ld = cl->classLoader;
   UserClassArray* res = ld->constructArray(name, cl);
   
-  // We are an initiating clas loader.
   if (res && res->classLoader != this) {
     classes->lock.lock();
     ClassMap::iterator End = classes->map.end();
@@ -573,7 +572,6 @@
       classes->map.insert(std::make_pair(res->name, res));
     classes->lock.unlock();
   }
-
   return res;
 }
 
@@ -592,12 +590,6 @@
     res = ((UserClass*)(I->second));
   }
   classes->lock.unlock();
-    
-  res->acquire();
-  if (!res->isClassRead()) res->readClass();
-  res->release();
-  
-
   return res;
 }
 
@@ -777,7 +769,7 @@
     if (!vmdata) {
       mvm::BumpPtrAllocator* A = new mvm::BumpPtrAllocator();    
       JCL = new(*A) JnjvmClassLoader(*A, *vm->bootstrapLoader, loader, vm);
-      vmdata = VMClassLoader::allocate(JCL);
+      vmdata = gc_new(VMClassLoader)(JCL);
       (upcalls->vmdataClassLoader->setObjectField(loader, (JavaObject*)vmdata));
     }
     loader->release();
@@ -1047,7 +1039,6 @@
     realCl->staticMethods = realCl->virtualMethods + realCl->nbVirtualMethods;
     realCl->staticFields = realCl->virtualFields + realCl->nbVirtualFields;
   }
-  cl->virtualVT->setNativeTracer(cl->virtualVT->tracer, "");
   JCL->getClasses()->map.insert(std::make_pair(cl->name, cl));
   cl->classLoader = JCL;
 }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JnjvmClassLoader.h Mon May  4 02:42:08 2009
@@ -399,30 +399,24 @@
 
 public:
 
-  static VMClassLoader* allocate(JnjvmClassLoader* J) {
-    VMClassLoader* res = 
-      (VMClassLoader*)gc::operator new(sizeof(VMClassLoader), &VT);
-    res->JCL = J;
-    return res;
-  }
-
   /// VT - The VirtualTable for this GC-class.
-  static VirtualTable VT;
+  static VirtualTable* VT;
 
   /// TRACER - Trace the internal class loader.
-  static void STATIC_TRACER(VMClassLoader) {
-    if (obj->JCL) obj->JCL->CALL_TRACER;
+  virtual void TRACER {
+    JCL->CALL_TRACER;
   }
 
   /// ~VMClassLoader - Delete the internal class loader.
   ///
-  static void staticDestructor(VMClassLoader* obj) {
-    if (obj->JCL) obj->JCL->~JnjvmClassLoader();
+  ~VMClassLoader() {
+    if (JCL) JCL->~JnjvmClassLoader();
   }
 
   /// VMClassLoader - Default constructors.
   ///
   VMClassLoader(JnjvmClassLoader* J) : JCL(J) {}
+  VMClassLoader() : JCL(0) {}
 
   /// getClassLoader - Get the internal class loader.
   ///

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Mon May  4 02:42:08 2009
@@ -57,17 +57,12 @@
 // Classpath with the vmdata field).
 //===----------------------------------------------------------------------===//
 
-VirtualTable VMClassLoader::VT((uintptr_t)VMClassLoader::staticDestructor,
-                               (uintptr_t)VMClassLoader::staticDestructor,
-                               (uintptr_t)VMClassLoader::staticTracer);
+#define INIT(X) VirtualTable* X::VT = 0
 
-VirtualTable LockObj::VT(0, 0, (uintptr_t)VirtualTable::emptyTracer);
+  INIT(LockObj);
+  INIT(VMClassLoader);
 
-//===----------------------------------------------------------------------===//
-// Empty tracer for static tracers of classes that do not declare static
-// variables.
-//===----------------------------------------------------------------------===//
-extern "C" void EmptyTracer(void*) {}
+#undef INIT
 
 //===----------------------------------------------------------------------===//
 // Root trace methods for Java objects. There are three types of roots:
@@ -161,8 +156,8 @@
   
   for (uint32 i =0; i < NR_ISOLATES; ++i) {
     TaskClassMirror &M = IsolateInfo[i];
-    if (M.staticInstance && staticTracer != EmptyTracer) {
-      staticTracer(M.staticInstance);
+    if (M.staticInstance) {
+      ((Class*)this)->staticTracer(M.staticInstance);
     }
   }
 }

Modified: vmkit/trunk/lib/Mvm/BoehmGC/MvmGC.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/BoehmGC/MvmGC.h?rev=70842&r1=70841&r2=70842&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/BoehmGC/MvmGC.h (original)
+++ vmkit/trunk/lib/Mvm/BoehmGC/MvmGC.h Mon May  4 02:42:08 2009
@@ -143,10 +143,6 @@
     if(GC_get_heap_size() < size)
     GC_expand_hp(size - GC_get_heap_size());
   }
-
-  static bool isLive() {
-    return true;
-  }
 };
 
 

Modified: vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h?rev=70842&r1=70841&r2=70842&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/MvmGC.h Mon May  4 02:42:08 2009
@@ -87,7 +87,6 @@
         static int      getTotalMemory(void);
         static void     setMaxMemory(size_t);
         static void     setMinMemory(size_t);
-  static bool isLive(void* ptr);
 };
 
 #endif

Modified: vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp?rev=70842&r1=70841&r2=70842&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gc.cpp Mon May  4 02:42:08 2009
@@ -173,10 +173,6 @@
 #endif
 }
 
-bool Collector::isLive(void* ptr) {
-  return GCCollector::isLive(ptr);
-}
-
 void GCThread::waitCollection() {
   mvm::Thread* th = mvm::Thread::get();
   unsigned int cm = GCCollector::current_mark;

Modified: vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp?rev=70842&r1=70841&r2=70842&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp Mon May  4 02:42:08 2009
@@ -71,42 +71,63 @@
 
   if(_marker)
     _marker(0);
-
-  
   status = stat_finalize;
-#ifdef HAVE_PTHREAD
-  threads->collectionFinished();
-#endif
-
-  VirtualMachine* vm = Thread::get()->MyVM;
-  
-  // Scan soft and weak reference queues.
-  vm->scanWeakReferencesQueue();
-  vm->scanSoftReferencesQueue();
 
-  // Scan finalization queue.
-  vm->scanFinalizationQueue();
-
-  // Now that the finalization queue has been scanned, scan the phantom queue.
-  vm->scanPhantomReferencesQueue();
-  
   /* finalize */
   GCChunkNode  finalizable;
   finalizable.attrape(unused_nodes);
 
+  status = stat_alloc;
+  
+  unlock();
+
   /* kill everyone */
   GCChunkNode *next = 0;
+
+#ifdef SERVICE
+  Thread* th = Thread::get();
+  VirtualMachine* OldVM = th->MyVM;
+#endif
+
+
+  for(cur=finalizable.next(); cur!=&finalizable; cur=next) {
+#ifdef SERVICE
+    mvm::VirtualMachine* NewVM = cur->meta;
+    if (NewVM) {
+      NewVM->memoryUsed -= real_nbb(cur);
+      th->MyVM = NewVM;
+      th->IsolateID = NewVM->IsolateID;
+    }
+#endif
+    register gc_header *c = cur->chunk();
+    next = cur->next();
+    
+    destructor_t dest = c->getDestructor();
+    if (dest) {
+      try {
+        dest(c);
+      } catch(...) {
+        mvm::Thread::get()->clearException();
+      }
+    }
+  }
+#ifdef SERVICE
+  th->IsolateID = OldVM->IsolateID;
+  th->MyVM = OldVM;
+#endif
+  
+  next = 0;
   for(cur=finalizable.next(); cur!=&finalizable; cur=next) {
     //printf("    !!!! reject %p [%p]\n", cur->chunk()->_2gc(), cur);
     next = cur->next();
     allocator->reject_chunk(cur);
   }
-  status = stat_alloc;
- 
-  // Collection finished. Wake up the finalizers if they are waiting.
-  Thread::get()->MyVM->wakeUpFinalizers();
 
+  lock();
 
+#ifdef HAVE_PTHREAD
+  threads->collectionFinished();
+#endif
 }
 
 void GCCollector::collect_unprotect() {

Modified: vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h?rev=70842&r1=70841&r2=70842&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h Mon May  4 02:42:08 2009
@@ -201,10 +201,6 @@
 
 
     unlock();
-
-    if (vt->destructor) 
-      mvm::Thread::get()->MyVM->addFinalizationCandidate((gc*)p->_2gc());
-
     return p->_2gc();
 #endif
   }
@@ -287,13 +283,6 @@
   static inline bool isMarked(GCChunkNode *node) { 
     return node->mark() == (current_mark & 1);
   }
-
-  static bool isLive(void* ptr) {
-    GCChunkNode *node = o2node(ptr);
-
-    if(node && isMarked(node)) return true;
-    else return false;
-  }
   
   static inline void mark(GCChunkNode *node) {
     node->_mark(current_mark & 1);

Modified: vmkit/trunk/lib/Mvm/Runtime/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/Runtime/Object.cpp?rev=70842&r1=70841&r2=70842&view=diff

==============================================================================
--- vmkit/trunk/lib/Mvm/Runtime/Object.cpp (original)
+++ vmkit/trunk/lib/Mvm/Runtime/Object.cpp Mon May  4 02:42:08 2009
@@ -14,14 +14,13 @@
 #include "mvm/Allocator.h"
 #include "mvm/Object.h"
 #include "mvm/PrintBuffer.h"
-#include "mvm/VirtualMachine.h"
 #include "mvm/Threads/Thread.h"
 
 using namespace mvm;
 
 
-VirtualTable NativeString::VT(0, 0, (uintptr_t)VirtualTable::emptyTracer);
-VirtualTable PrintBuffer::VT(0, 0, (uintptr_t)PrintBuffer::staticTracer);
+VirtualTable *NativeString::VT = 0;
+VirtualTable *PrintBuffer::VT = 0;
 
 extern "C" void printFloat(float f) {
   fprintf(stderr, "%f\n", f);
@@ -44,6 +43,22 @@
 }
 
 
+void Object::initialise() {
+# define INIT(X) { \
+  X fake; \
+  X::VT = ((VirtualTable**)(void*)(&fake))[0]; }
+  
+  INIT(NativeString);
+  INIT(PrintBuffer);
+  
+#undef INIT
+}
+
+void PrintBuffer::TRACER {
+  ((PrintBuffer *)this)->contents()->MARK_AND_TRACE;
+}
+
+
 PrintBuffer *PrintBuffer::writeObj(const Object *obj) {
   Object *beg = (Object*)Collector::begOf(obj);
   
@@ -113,136 +128,3 @@
   }
   buf->write("\"");
 }
-
-
-void VirtualMachine::finalizerStart(mvm::Thread* th) {
-  VirtualMachine* vm = th->MyVM;
-
-  while (true) {
-    vm->FinalizationLock.lock();
-    while (vm->CurrentFinalizedIndex == 0) {
-      vm->FinalizationCond.wait(&vm->FinalizationLock);
-    }
-    vm->FinalizationLock.unlock();
-
-    while (true) {
-      vm->FinalizationQueueLock.acquire();
-      gc* res = 0;
-      if (vm->CurrentFinalizedIndex != 0) {
-        res = vm->ToBeFinalized[--vm->CurrentFinalizedIndex];
-      }
-      vm->FinalizationQueueLock.release();
-      if (!res) break;
-
-      VirtualTable* VT = res->getVirtualTable();
-      try {
-        if (VT->operatorDelete) {
-          // It's a native method!
-          destructor_t dest = (destructor_t)VT->destructor;
-          dest(res);
-        } else {
-          vm->invokeFinalizer(res);
-        }
-      } catch(...) {
-      }
-    }
-  }
-}
-
-void VirtualMachine::growQueue() {
-  if (CurrentIndex >= QueueLength) {
-    uint32 newLength = QueueLength * GROW_FACTOR;
-    gc** newQueue = new gc*[newLength];
-    for (uint32 i = 0; i < QueueLength; ++i) newQueue[i] = FinalizationQueue[i];
-    delete[] FinalizationQueue;
-    FinalizationQueue = newQueue;
-    QueueLength = newLength;
-    
-    newLength = ToBeFinalizedLength * GROW_FACTOR;
-    newQueue = new gc*[newLength];
-    for (uint32 i = 0; i < ToBeFinalizedLength; ++i) newQueue[i] = ToBeFinalized[i];
-    delete[] ToBeFinalized;
-    ToBeFinalized = newQueue;
-    ToBeFinalizedLength = newLength;
-  }
-}
-
-
-void VirtualMachine::addFinalizationCandidate(gc* obj) {
-  FinalizationQueueLock.acquire();
- 
-  if (CurrentIndex >= QueueLength) {
-    growQueue();
-  }
-  
-  FinalizationQueue[CurrentIndex++] = obj;
-  FinalizationQueueLock.release();
-}
-
-void VirtualMachine::scanFinalizationQueue() {
-  FinalizationQueueLock.acquire();
-  uint32 NewIndex = 0;
-  for (uint32 i = 0; i < CurrentIndex; ++i) {
-    gc* obj = FinalizationQueue[i];
-
-    if (!Collector::isLive(obj)) {
-      obj->markAndTrace();
-      
-      if (CurrentFinalizedIndex >= ToBeFinalizedLength) growQueue();
-      
-      /* Add to object table */
-      ToBeFinalized[CurrentFinalizedIndex++] = obj;
-    } else {
-      FinalizationQueue[NewIndex++] = obj;
-    }
-  }
-  CurrentIndex = NewIndex;
-
-  for (uint32 i = 0; i < CurrentFinalizedIndex; ++i) {
-    gc* obj = ToBeFinalized[i];
-    obj->markAndTrace();
-  }
-  FinalizationQueueLock.release();
-
-}
-
-gc* ReferenceQueue::processReference(gc* reference, VirtualMachine* vm) {
-  if (!Collector::isLive(reference)) {
-    vm->clearReferent(reference);
-    return 0;
-  }
-
-  gc* referent = vm->getReferent(reference);
-
-  if (!referent) return 0;
-
-  if (semantics == SOFT) {
-    // TODO: are we are out of memory? Consider that we always are for now.
-    if (false) {
-      referent->markAndTrace();
-    }
-  } else if (semantics == PHANTOM) {
-    // Nothing to do.
-  }
-
-  if (Collector::isLive(referent)) {
-    return reference;
-  } else {
-    vm->clearReferent(reference);
-    vm->enqueueReference(reference);
-    return 0;
-  }
-}
-
-
-void ReferenceQueue::scan(VirtualMachine* vm) {
-  uint32 NewIndex = 0;
-
-  for (uint32 i = 0; i < CurrentIndex; ++i) {
-    gc* obj = References[i];
-    processReference(obj, vm);
-  }
-
-  CurrentIndex = NewIndex;
-
-}

Modified: vmkit/trunk/tools/jnjvm/Main.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/jnjvm/Main.cpp?rev=70842&r1=70841&r2=70842&view=diff

==============================================================================
--- vmkit/trunk/tools/jnjvm/Main.cpp (original)
+++ vmkit/trunk/tools/jnjvm/Main.cpp Mon May  4 02:42:08 2009
@@ -27,6 +27,7 @@
   llvm::llvm_shutdown_obj X;  
     
   MvmModule::initialise();
+  Object::initialise();
   Collector::initialise(0);
  
   JavaJITCompiler* Comp = new JavaJITCompiler("JITModule");

Modified: vmkit/trunk/tools/n3-mono/Main.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/n3-mono/Main.cpp?rev=70842&r1=70841&r2=70842&view=diff

==============================================================================
--- vmkit/trunk/tools/n3-mono/Main.cpp (original)
+++ vmkit/trunk/tools/n3-mono/Main.cpp Mon May  4 02:42:08 2009
@@ -21,6 +21,7 @@
   llvm::llvm_shutdown_obj X;  
     
   MvmModule::initialise();
+  Object::initialise();
   Collector::initialise(0);
 
   VirtualMachine::initialiseCLIVM();

Modified: vmkit/trunk/tools/n3-pnetlib/Main.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/n3-pnetlib/Main.cpp?rev=70842&r1=70841&r2=70842&view=diff

==============================================================================
--- vmkit/trunk/tools/n3-pnetlib/Main.cpp (original)
+++ vmkit/trunk/tools/n3-pnetlib/Main.cpp Mon May  4 02:42:08 2009
@@ -21,6 +21,7 @@
   llvm::llvm_shutdown_obj X;  
     
   MvmModule::initialise();
+  Object::initialise();
   Collector::initialise(0);
 
   VirtualMachine::initialiseCLIVM();

Modified: vmkit/trunk/tools/vmjc/vmjc.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmjc/vmjc.cpp?rev=70842&r1=70841&r2=70842&view=diff

==============================================================================
--- vmkit/trunk/tools/vmjc/vmjc.cpp (original)
+++ vmkit/trunk/tools/vmjc/vmjc.cpp Mon May  4 02:42:08 2009
@@ -213,6 +213,7 @@
       Comp = new JavaJITCompiler("JIT");
     }
 
+    mvm::Object::initialise();
     Collector::initialise(0);
     Collector::enable(0);
 

Modified: vmkit/trunk/tools/vmkit/Launcher.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/tools/vmkit/Launcher.cpp?rev=70842&r1=70841&r2=70842&view=diff

==============================================================================
--- vmkit/trunk/tools/vmkit/Launcher.cpp (original)
+++ vmkit/trunk/tools/vmkit/Launcher.cpp Mon May  4 02:42:08 2009
@@ -133,6 +133,7 @@
   }
   
   mvm::MvmModule::initialise(Fast);
+  mvm::Object::initialise();
   Collector::initialise(0);
 
   if (VMToRun == RunJava) {





More information about the vmkit-commits mailing list