[vmkit-commits] [vmkit] r84467 - in /vmkit/trunk/lib/JnJVM: Classpath/ClasspathReflect.h Classpath/ClasspathVMThread.inc Compiler/JavaJITOpcodes.cpp VMCore/JavaLocks.h VMCore/JavaObject.cpp VMCore/JavaObject.h VMCore/JavaThread.h VMCore/Jnjvm.cpp VMCore/VirtualTables.cpp

Nicolas Geoffray nicolas.geoffray at lip6.fr
Sun Oct 18 23:59:21 PDT 2009


Author: geoffray
Date: Mon Oct 19 01:59:21 2009
New Revision: 84467

URL: http://llvm.org/viewvc/llvm-project?rev=84467&view=rev
Log:
Get rid of LockObj to create a JavaLock that will be
permanently allocated and recycled across JavaObjects.


Added:
    vmkit/trunk/lib/JnJVM/VMCore/JavaLocks.h
Modified:
    vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h
    vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThread.inc
    vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h
    vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
    vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathReflect.h Mon Oct 19 01:59:21 2009
@@ -35,7 +35,6 @@
   }
 
   static void staticTracer(JavaObjectClass* obj) {
-    obj->traceLock();
     obj->pd->markAndTrace();
     obj->signers->markAndTrace();
     obj->constructor->markAndTrace();
@@ -56,7 +55,6 @@
 public:
 
   static void staticTracer(JavaObjectField* obj) {
-    obj->traceLock();
     obj->name->markAndTrace();
     obj->declaringClass->markAndTrace();
   }
@@ -81,7 +79,6 @@
 public:
   
   static void staticTracer(JavaObjectMethod* obj) {
-    obj->traceLock();
     obj->name->markAndTrace();
     obj->declaringClass->markAndTrace();
   }
@@ -104,7 +101,6 @@
 
 public:
   static void staticTracer(JavaObjectConstructor* obj) {
-    obj->traceLock();
     obj->clazz->markAndTrace();
   }
   

Modified: vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThread.inc
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThread.inc?rev=84467&r1=84466&r2=84467&view=diff

==============================================================================
--- vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThread.inc (original)
+++ vmkit/trunk/lib/JnJVM/Classpath/ClasspathVMThread.inc Mon Oct 19 01:59:21 2009
@@ -120,7 +120,7 @@
   
   JavaThread* th = (JavaThread*)field->getObjectField(vmthread);
   th->interruptFlag = 1;
-  LockObj* lock = th->waitsOn;
+  JavaLock* lock = th->waitsOn;
 
   // If the thread is blocked on a wait. We also verify nextWaiting in case
   // the thread has been notified.

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp (original)
+++ vmkit/trunk/lib/JnJVM/Compiler/JavaJITOpcodes.cpp Mon Oct 19 01:59:21 2009
@@ -7,9 +7,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#define DEBUG 0
+#define DEBUG 2
 #define JNJVM_COMPILE 0
-#define JNJVM_EXECUTE 0
+#define JNJVM_EXECUTE 2
 
 #include <cstring>
 

Added: vmkit/trunk/lib/JnJVM/VMCore/JavaLocks.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/JnJVM/VMCore/JavaLocks.h?rev=84467&view=auto

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaLocks.h (added)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaLocks.h Mon Oct 19 01:59:21 2009
@@ -0,0 +1,92 @@
+//===--------------- JavaLocks.h - Fat lock management --------------------===//
+//
+//                            The VMKit project
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef JAVA_LOCKS_H
+#define JAVA_LOCKS_H
+
+#include "mvm/Allocator.h"
+#include "mvm/Threads/Locks.h"
+
+namespace mvm {
+  class Thread;
+}
+
+namespace jnjvm {
+
+class JavaObject;
+class JavaThread;
+
+class JavaLock : public mvm::PermanentObject {
+
+friend class JavaObject;
+
+private:
+  mvm::LockRecursive internalLock;
+  mvm::Thread* waitingThread;
+  JavaThread* firstThread;
+  JavaObject* associatedObject;
+  uint32_t index;
+
+public:
+
+  /// acquire - Acquires the internalLock.
+  ///
+  void acquire() {
+    waitingThread = mvm::Thread::get();
+    internalLock.lock();
+    waitingThread = 0;
+  }
+ 
+  /// tryAcquire - Tries to acquire the lock.
+  ///
+  int tryAcquire() {
+    return internalLock.tryLock();
+  }
+
+ 
+  /// acquireAll - Acquires the lock nb times.
+  void acquireAll(uint32 nb) {
+    waitingThread = mvm::Thread::get();
+    internalLock.lockAll(nb);
+    waitingThread = 0;
+  }
+
+  /// release - Releases the internalLock.
+  ///
+  void release() {
+    internalLock.unlock();
+  }
+  
+  /// owner - Returns if the current thread owns this internalLock.
+  ///
+  bool owner() {
+    return internalLock.selfOwner();
+  }
+ 
+  /// getOwner - Get the owner of this internalLock.
+  ///
+  mvm::Thread* getOwner() {
+    return internalLock.getOwner();
+  }
+  
+  /// JavaLock - Empty constructor.
+  JavaLock(uint32_t i) {
+    firstThread = 0;
+    index = i;
+    associatedObject = 0;
+    waitingThread = 0;
+  }
+
+  static JavaLock* allocate(JavaObject*);
+  
+};
+
+}
+
+#endif

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp Mon Oct 19 01:59:21 2009
@@ -18,27 +18,10 @@
 
 using namespace jnjvm;
 
-LockObj* LockObj::allocate(JavaObject* owner) {
-  llvm_gcroot(owner, 0);
-#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);
-#endif
-  assert(!res->firstThread && "Error in constructor");
-  return res;
-}
-
 void JavaObject::waitIntern(struct timeval* info, bool timed) {
-  LockObj* l = 0;
+  JavaLock* l = 0;
   JavaObject* self = this;
   llvm_gcroot(self, 0);
-  llvm_gcroot(l, 0);
 
   if (owner()) {
     l = self->lock.changeToFatlock(self);
@@ -76,10 +59,10 @@
 
       while (!thread->interruptFlag && thread->nextWaiting) {
         if (timed) {
-          timeout = varcondThread.timedWait(&l->lock, info);
+          timeout = varcondThread.timedWait(&l->internalLock, info);
           if (timeout) break;
         } else {
-          varcondThread.wait(&l->lock);
+          varcondThread.wait(&l->internalLock);
         }
       }
      
@@ -145,10 +128,9 @@
 }
 
 void JavaObject::notify() {
-  LockObj* l = 0;
+  JavaLock* l = 0;
   JavaObject* self = this;
   llvm_gcroot(self, 0);
-  llvm_gcroot(l, 0);
 
   if (owner()) {
     l = self->lock.getFatLock();
@@ -191,10 +173,9 @@
 }
 
 void JavaObject::notifyAll() {
-  LockObj* l = 0;
+  JavaLock* l = 0;
   JavaObject* self = this;
   llvm_gcroot(self, 0);
-  llvm_gcroot(l, 0);
   
   if (owner()) {
     l = self->lock.getFatLock();

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h Mon Oct 19 01:59:21 2009
@@ -16,6 +16,7 @@
 
 #include "types.h"
 
+#include "JavaLocks.h"
 #include "JnjvmConfig.h"
 
 namespace jnjvm {
@@ -26,79 +27,6 @@
 class Typedef;
 class UserCommonClass;
 
-/// LockObj - This class represents a Java monitor.
-///
-class LockObj : public gc {
-  friend class JavaObject;
-private:
-
-
-  /// lock - The internal lock of this object lock.
-  ///
-  mvm::LockRecursive lock;
-
-  /// firstThread - The first thread doing a wait.
-  ///
-  JavaThread* firstThread;
-
-public:
-  /// allocate - Allocates a lock object. Only the internal lock is allocated.
-  ///
-  static LockObj* allocate(JavaObject*);
-  
-  /// acquire - Acquires the lock.
-  ///
-  void acquire() {
-    LockObj* self = this;
-    llvm_gcroot(self, 0);
-    self->lock.lock();
-  }
-  
-  /// tryAcquire - Tries to acquire the lock.
-  ///
-  int tryAcquire() {
-    return lock.tryLock();
-  }
-  
-  /// acquireAll - Acquires the lock nb times.
-  void acquireAll(uint32 nb) {
-    LockObj* self = this;
-    llvm_gcroot(self, 0);
-    self->lock.lockAll(nb);
-  }
-
-  /// release - Releases the lock.
-  ///
-  void release() {
-    lock.unlock();
-  }
-  
-  /// owner - Returns if the current thread owns this lock.
-  ///
-  bool owner() {
-    return lock.selfOwner();
-  }
- 
-  /// getOwner - Get the owner of this lock.
-  ///
-  mvm::Thread* getOwner() {
-    return lock.getOwner();
-  }
-  
-  /// VT - LockObj is GC-allocated, so we must make the VT explicit.
-  ///
-  static VirtualTable VT;
-
-  /// staticDestructor - The destructor of this LockObj, called by the GC.
-  ///
-  static void staticDestructor(LockObj* obj) {
-    obj->lock.~LockRecursive();
-  }
-
-  /// LockObj - Empty constructor.
-  LockObj() { firstThread = 0; }
-};
-
 /// JavaVirtualTable - This class is the virtual table of instances of
 /// Java classes. Besides holding function pointers for virtual calls,
 /// it contains a bunch of information useful for fast dynamic type checking.
@@ -270,7 +198,7 @@
 
   /// lock - The monitor of this object. Most of the time null.
   ///
-  mvm::ThinLock<LockObj, JavaObject, mvm::FatLockWithGC> lock;
+  mvm::ThinLock<JavaLock, JavaObject, mvm::FatLockNoGC> lock;
 
   /// wait - Java wait. Makes the current thread waiting on a monitor.
   ///
@@ -327,7 +255,7 @@
 #endif
   
   /// lockObj - Get the LockObj if the lock is a fat lock.
-  LockObj* lockObj() {
+  JavaLock* lockObj() {
     return lock.getFatLock();
   }
 
@@ -336,10 +264,6 @@
   ///
   void decapsulePrimitive(Jnjvm* vm, uintptr_t &buf, const Typedef* signature);
 
-  void traceLock() {
-    LockObj* l = lockObj();
-    if (l) l->markAndTrace();
-  }
 };
 
 

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaThread.h Mon Oct 19 01:59:21 2009
@@ -29,7 +29,6 @@
 class JavaMethod;
 class JavaObject;
 class Jnjvm;
-class LockObj;
 
 
 #define BEGIN_NATIVE_EXCEPTION(level) \
@@ -119,7 +118,7 @@
 
   /// waitsOn - The monitor on which the thread is waiting on.
   ///
-  LockObj* waitsOn;
+  JavaLock* waitsOn;
 
   static const unsigned int StateRunning;
   static const unsigned int StateWaiting;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Mon Oct 19 01:59:21 2009
@@ -1389,3 +1389,11 @@
   
   return 0; 
 }
+
+
+JavaLock* JavaLock::allocate(JavaObject* obj) {
+  Jnjvm* vm = JavaThread::get()->getJVM();
+  JavaLock* res = new(vm->allocator, "Lock") JavaLock(0);
+  res->associatedObject = obj;
+  return res;
+}

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/VirtualTables.cpp Mon Oct 19 01:59:21 2009
@@ -59,10 +59,6 @@
                                (uintptr_t)VMClassLoader::staticDestructor,
                                (uintptr_t)VMClassLoader::staticTracer);
 
-VirtualTable LockObj::VT((uintptr_t)LockObj::staticDestructor,
-                         (uintptr_t)LockObj::staticDestructor,
-                         (uintptr_t)VirtualTable::emptyTracer);
-
 //===----------------------------------------------------------------------===//
 // Empty tracer for static tracers of classes that do not declare static
 // variables.
@@ -85,8 +81,6 @@
 
 /// Method for scanning the root of an object.
 extern "C" void JavaObjectTracer(JavaObject* obj) {
-  obj->traceLock();
-  
   CommonClass* cl = obj->getClass();
   assert(cl && "No class");
   cl->classLoader->getJavaClassLoader()->markAndTrace();
@@ -95,8 +89,6 @@
 /// Method for scanning an array whose elements are JavaObjects. This method is
 /// called by all non-native Java arrays.
 extern "C" void ArrayObjectTracer(ArrayObject* obj) {
-  obj->traceLock();
-  
   CommonClass* cl = obj->getClass();
   assert(cl && "No class");
   cl->classLoader->getJavaClassLoader()->markAndTrace();
@@ -111,13 +103,10 @@
 /// the class is the bootstrap loader and therefore does not need to be
 /// scanned here.
 extern "C" void JavaArrayTracer(JavaArray* obj) {
-  obj->traceLock();
 }
 
 /// Method for scanning regular objects.
 extern "C" void RegularObjectTracer(JavaObject* obj) {
-  obj->traceLock();
-
   Class* cl = obj->getClass()->asClass();
   assert(cl && "Not a class in regular tracer");
   cl->classLoader->getJavaClassLoader()->markAndTrace();
@@ -222,9 +211,6 @@
     for (uint32 i = 0; i < end->length; ++i) {
       JavaObject* obj = end->strings[i];
       obj->markAndTrace(); 
-      // If the string was static allocated, we want to trace its lock.
-      LockObj* l = obj->lockObj();
-      if (l) l->markAndTrace();
     }
     end = end->prev;
   }





More information about the vmkit-commits mailing list