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

Nicolas Geoffray nicolas.geoffray at lip6.fr
Sun Oct 4 08:40:28 PDT 2009


Author: geoffray
Date: Sun Oct  4 10:40:28 2009
New Revision: 83278

URL: http://llvm.org/viewvc/llvm-project?rev=83278&view=rev
Log:
Use a new class template for ThinLock to express if the FatLock
is a GC object or not.


Modified:
    vmkit/trunk/include/mvm/Threads/Locks.h
    vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h
    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=83278&r1=83277&r2=83278&view=diff

==============================================================================
--- vmkit/trunk/include/mvm/Threads/Locks.h (original)
+++ vmkit/trunk/include/mvm/Threads/Locks.h Sun Oct  4 10:40:28 2009
@@ -187,18 +187,45 @@
   static const uint64_t ThinCountMask = 0xFF;
 
 
+
+#ifdef WITH_LLVM_GCC
+extern "C" void __llvm_gcroot(const void**, void*) __attribute__((nothrow));
+#define llvm_gcroot(a, b) __llvm_gcroot((const void**)&a, b)
+#else
+#define llvm_gcroot(a, b)
+#endif
+
+  class FatLockNoGC {
+  public:
+    static void gcroot(void* val, void* unused) 
+      __attribute__ ((always_inline)) {}
+  };
+  
+  class FatLockWithGC {
+  public:
+    static void gcroot(void* val, void* unused) 
+      __attribute__ ((always_inline)) {
+      llvm_gcroot(val, unused);
+    }
+  };
+
+
 /// ThinLock - This class is an implementation of thin locks. The template class
 /// TFatLock is a virtual machine specific fat lock.
 ///
-template <class TFatLock, class Owner>
+template <class TFatLock, class Owner, class IsGC>
 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(Owner* O = 0) {
     TFatLock* obj = TFatLock::allocate(O);
+    IsGC::gcroot(obj, 0);
     obj->acquireAll(257);
     lock = ((uintptr_t)obj >> 1) | FatMask;
   }
@@ -221,6 +248,7 @@
   TFatLock* changeToFatlock(Owner* O) {
     if (!(lock & FatMask)) {
       TFatLock* obj = TFatLock::allocate(O);
+      IsGC::gcroot(obj, 0);
       size_t val = (((size_t) obj) >> 1) | FatMask;
       uint32 count = lock & ThinCountMask;
       obj->acquireAll(count + 1);
@@ -247,6 +275,7 @@
           }
         } else {
           TFatLock* obj = TFatLock::allocate(O);
+          IsGC::gcroot(obj, 0);
           uintptr_t val = ((uintptr_t)obj >> 1) | FatMask;
 loop:
           while (lock) {
@@ -282,6 +311,7 @@
       lock = 0;
     } else if (lock & FatMask) {
       TFatLock* obj = (TFatLock*)(lock << 1);
+      IsGC::gcroot(obj, 0);
       obj->release();
     } else {
       lock--;
@@ -293,6 +323,7 @@
   void broadcast() {
     if (lock & FatMask) {
       TFatLock* obj = (TFatLock*)(lock << 1);
+      IsGC::gcroot(obj, 0);
       obj->broadcast();
     }
   }
@@ -301,6 +332,7 @@
   void signal() {
     if (lock & FatMask) {
       TFatLock* obj = (TFatLock*)(lock << 1);
+      IsGC::gcroot(obj, 0);
       obj->signal();
     }
   }
@@ -313,6 +345,7 @@
     if ((lock & ThinMask) == id) return true;
     if (lock & FatMask) {
       TFatLock* obj = (TFatLock*)(lock << 1);
+      IsGC::gcroot(obj, 0);
       return obj->owner();
     }
     return false;
@@ -321,6 +354,7 @@
   mvm::Thread* getOwner() {
     if (lock & FatMask) {
       TFatLock* obj = (TFatLock*)(lock << 1);
+      IsGC::gcroot(obj, 0);
       return obj->getOwner();
     } else {
       return (mvm::Thread*)(lock & ThinMask);

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaClass.h Sun Oct  4 10:40:28 2009
@@ -387,7 +387,7 @@
 class Class : public CommonClass {
 
 private:
-
+ 
   /// FatLock - This class is the inflated lock of Class instances. It should
   /// be very rare that such locks are allocated.
   class FatLock : public mvm::PermanentObject {
@@ -448,7 +448,7 @@
   /// lock - The lock of this class. It should be very rare that this lock
   /// inflates.
   ///
-  mvm::ThinLock<FatLock, CommonClass> lock;
+  mvm::ThinLock<FatLock, CommonClass, mvm::FatLockNoGC> lock;
   
   /// virtualFields - List of all the virtual fields defined in this class.
   /// This does not contain non-redefined super fields.

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h Sun Oct  4 10:40:28 2009
@@ -270,7 +270,7 @@
 
   /// lock - The monitor of this object. Most of the time null.
   ///
-  mvm::ThinLock<LockObj, JavaObject> lock;
+  mvm::ThinLock<LockObj, JavaObject, mvm::FatLockWithGC> lock;
 
   /// wait - Java wait. Makes the current thread waiting on a monitor.
   ///





More information about the vmkit-commits mailing list