[vmkit-commits] [vmkit] r60126 - in /vmkit/trunk: include/mvm/Threads/Locks.h lib/JnJVM/VMCore/JavaClass.h lib/JnJVM/VMCore/JavaObject.cpp lib/JnJVM/VMCore/JavaObject.h

Nicolas Geoffray nicolas.geoffray at lip6.fr
Wed Nov 26 14:49:49 PST 2008


Author: geoffray
Date: Wed Nov 26 16:49:49 2008
New Revision: 60126

URL: http://llvm.org/viewvc/llvm-project?rev=60126&view=rev
Log:
Also implement thin lock for classes.


Modified:
    vmkit/trunk/include/mvm/Threads/Locks.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h

Modified: vmkit/trunk/include/mvm/Threads/Locks.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Locks.h?rev=60126&r1=60125&r2=60126&view=diff

==============================================================================
--- vmkit/trunk/include/mvm/Threads/Locks.h (original)
+++ vmkit/trunk/include/mvm/Threads/Locks.h Wed Nov 26 16:49:49 2008
@@ -84,15 +84,15 @@
 /// a comparison and not an expensive compare and swap. The template class
 /// TFatLock is a virtual machine specific fat lock.
 ///
-template <class TFatLock>
+template <class TFatLock, class Owner>
 class ThinLock {
   uintptr_t lock;
 
 public:
   /// overflowThinlock - Change the lock of this object to a fat lock because
   /// we have reached 0xFF locks.
-  void overflowThinLock() {
-    TFatLock* obj = TFatLock::allocate();
+  void overflowThinLock(Owner* O = 0) {
+    TFatLock* obj = TFatLock::allocate(O);
     obj->acquireAll(256);
     lock = ((uintptr_t)obj >> 1) | FatMask;
   }
@@ -112,9 +112,9 @@
   
   /// changeToFatlock - Change the lock of this object to a fat lock. The lock
   /// may be in a thin lock or fat lock state.
-  TFatLock* changeToFatlock() {
+  TFatLock* changeToFatlock(Owner* O) {
     if (!(lock & FatMask)) {
-      TFatLock* obj = TFatLock::allocate();
+      TFatLock* obj = TFatLock::allocate(O);
       uintptr_t val = ((uintptr_t)obj >> 1) | FatMask;
       uint32 count = lock & ThinCountMask;
       obj->acquireAll(count);
@@ -127,7 +127,7 @@
  
 
   /// acquire - Acquire the lock.
-  void acquire() {
+  void acquire(Owner* O = 0) {
     uint64_t id = mvm::Thread::get()->getThreadID();
     if ((lock & ReservedMask) == id) {
       lock |= 1;
@@ -149,7 +149,7 @@
           TFatLock* obj = (TFatLock*)(lock << 1);
           obj->acquire();
         } else {
-          TFatLock* obj = TFatLock::allocate();
+          TFatLock* obj = TFatLock::allocate(O);
           val = ((uintptr_t)obj >> 1) | FatMask;
           uint32 count = 0;
 loop:

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Wed Nov 26 16:49:49 2008
@@ -138,6 +138,44 @@
 friend class UserCommonClass;
 #endif
 
+private:
+  class FatLock : public mvm::PermanentObject {
+  public:
+    /// lockVar - When multiple threads want to load/resolve/initialize a class,
+    /// they must be synchronized so that these steps are only performed once
+    /// for a given class.
+    mvm::LockRecursive lockVar;
+
+    /// condVar - Used to wake threads waiting on the load/resolve/initialize
+    /// process of this class, done by another thread.
+    mvm::Cond condVar;
+    
+
+    static FatLock* allocate(UserCommonClass* cl) {
+      return new(cl->classLoader->allocator) FatLock();
+    }
+
+    void acquire() {
+      lockVar.lock();
+    }
+
+    void acquireAll(uint32 nb) {
+      lockVar.lockAll(nb);
+    }
+
+    void release() {
+      lockVar.unlock();
+    }
+
+    void broadcast() {
+      condVar.broadcast();
+    }
+
+    void wait() {
+      condVar.wait(&lockVar);
+    }
+  };
+
 public:
   
 //===----------------------------------------------------------------------===//
@@ -211,16 +249,7 @@
   /// super - The parent of this class.
   ///
   CommonClass * super;
-  
-  /// lockVar - When multiple threads want to load/resolve/initialize a class,
-  /// they must be synchronized so that these steps are only performed once
-  /// for a given class.
-  mvm::LockRecursive lockVar;
-
-  /// condVar - Used to wake threads waiting on the load/resolve/initialize
-  /// process of this class, done by another thread.
-  mvm::Cond condVar;
-  
+   
   /// classLoader - The Jnjvm class loader that loaded the class.
   ///
   JnjvmClassLoader* classLoader;
@@ -249,6 +278,11 @@
   ///
   mvm::Thread* ownerClass;
  
+  /// lock - The lock of this class. It should be very rare that this lock
+  /// inflates.
+  ///
+  mvm::ThinLock<FatLock, CommonClass> lock;
+
   // Assessor methods.
   uint32 getVirtualSize()         { return virtualSize; }
   VirtualTable* getVirtualVT()    { return virtualVT; }
@@ -318,26 +352,27 @@
   /// acquire - Acquire this class lock.
   ///
   void acquire() {
-    lockVar.lock();
+    lock.acquire(this);
   }
   
   /// release - Release this class lock.
   ///
   void release() {
-    lockVar.unlock();  
+    lock.release();  
   }
 
   /// waitClass - Wait for the class to be loaded/initialized/resolved.
   ///
   void waitClass() {
-    condVar.wait(&lockVar);
+    FatLock* FL = lock.changeToFatlock(this);
+    FL->wait();
   }
   
   /// broadcastClass - Unblock threads that were waiting on the class being
   /// loaded/initialized/resolved.
   ///
   void broadcastClass() {
-    condVar.broadcast();  
+    lock.broadcast();  
   }
   
   /// getOwnerClass - Get the thread that is currently initializing the class.

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp Wed Nov 26 16:49:49 2008
@@ -65,7 +65,7 @@
   }
 }
 
-LockObj* LockObj::allocate() {
+LockObj* LockObj::allocate(JavaObject* owner) {
 #ifdef USE_GC_BOEHM
   LockObj* res = new LockObj();
 #else
@@ -83,7 +83,7 @@
 void JavaObject::waitIntern(struct timeval* info, bool timed) {
 
   if (owner()) {
-    LockObj * l = lock.changeToFatlock();
+    LockObj * l = lock.changeToFatlock(this);
     JavaThread* thread = JavaThread::get();
     mvm::Lock& mutexThread = thread->lock;
     mvm::Cond& varcondThread = thread->varcond;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h Wed Nov 26 16:49:49 2008
@@ -75,7 +75,7 @@
 public:
   /// allocate - Allocates a lock object. Only the internal lock is allocated.
   ///
-  static LockObj* allocate();
+  static LockObj* allocate(JavaObject*);
   
   /// acquire - Acquires the lock.
   ///
@@ -133,7 +133,7 @@
 
   /// lock - The monitor of this object. Most of the time null.
   ///
-  mvm::ThinLock<LockObj> lock;
+  mvm::ThinLock<LockObj, JavaObject> lock;
 
   /// wait - Java wait. Makes the current thread waiting on a monitor.
   ///





More information about the vmkit-commits mailing list