[llvm-commits] [vmkit] r51715 - in /vmkit/trunk/lib/JnJVM/VMCore: JavaObject.cpp JavaObject.h

Nicolas Geoffray nicolas.geoffray at lip6.fr
Thu May 29 16:48:41 PDT 2008


Author: geoffray
Date: Thu May 29 18:48:41 2008
New Revision: 51715

URL: http://llvm.org/viewvc/llvm-project?rev=51715&view=rev
Log:
Clean-up and document.


Modified:
    vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp
    vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.cpp Thu May 29 18:48:41 2008
@@ -24,10 +24,6 @@
 
 mvm::Lock* JavaObject::globalLock = 0;
 
-JavaCond* JavaCond::allocate() {
-  return new JavaCond();
-}
-
 void JavaCond::notify() {
   for (std::vector<JavaThread*>::iterator i = threads.begin(), 
             e = threads.end(); i!= e;) {
@@ -81,7 +77,7 @@
 LockObj* LockObj::allocate() {
   LockObj* res = vm_new(JavaThread::get()->isolate, LockObj)();
   res->lock = mvm::Lock::allocRecursive();
-  res->varcond = JavaCond::allocate();
+  res->varcond = 0;
   return res;
 }
 
@@ -133,7 +129,8 @@
       unsigned int recur = mvm::LockRecursive::recursion_count(l->lock);
       bool timeout = false;
       mvm::LockRecursive::my_unlock_all(l->lock);
-      l->varcond->wait(thread);
+      JavaCond* cond = l->getCond();
+      cond->wait(thread);
       thread->state = JavaThread::StateWaiting;
 
       if (timed) {
@@ -147,7 +144,7 @@
       mvm::LockRecursive::my_lock_all(l->lock, recur);
 
       if (interrupted || timeout) {
-        l->varcond->remove(thread);
+        cond->remove(thread);
       }
 
       thread->state = JavaThread::StateRunning;
@@ -173,7 +170,7 @@
 void JavaObject::notify() {
   LockObj* l = LockObj::myLock(this);
   if (l->owner()) {
-    l->varcond->notify();
+    l->getCond()->notify();
   } else {
     JavaThread::get()->isolate->illegalMonitorStateException(this);
   }
@@ -182,13 +179,13 @@
 void JavaObject::notifyAll() {
   LockObj* l = LockObj::myLock(this);
   if (l->owner()) {
-    l->varcond->notifyAll();
+    l->getCond()->notifyAll();
   } else {
     JavaThread::get()->isolate->illegalMonitorStateException(this);
   } 
 }
 
 void LockObj::destroyer(size_t sz) {
-  delete varcond;
+  if (varcond) delete varcond;
   delete lock;
 }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/JavaObject.h Thu May 29 18:48:41 2008
@@ -26,63 +26,144 @@
 class JavaThread;
 class UTF8;
 
+/// JavaCond - This class maintains a list of threads blocked on a wait. 
+/// notify and notifyAll will change the state of one or more of these threads.
+///
 class JavaCond {
-public:
-  std::vector<JavaThread*> threads;
+private:
   
-  static JavaCond* allocate();
+  /// threads - The list of threads currently waiting.
+  ///
+  std::vector<JavaThread*> threads;
 
+public:
+  
+  /// notify - The Java notify: takes the first thread in the list and wakes
+  /// it up.
   void notify();
+  
+  /// notifyAll - The Java notifyAll: wakes all threads in the list.
+  ///
   void notifyAll();
+
+  /// wait - The Java wait: the thread blocks waiting to be notified.
+  ///
   void wait(JavaThread* th);
+
+  /// remove - Remove the thread from the list. This is called by threads being
+  /// interrupted or timed out on a wait.
   void remove(JavaThread* th);
 };
 
 
+/// LockObj - This class represents a Java monitor.
+///
 class LockObj : public mvm::Object {
 public:
+
   static VirtualTable* VT;
+
+  /// lock - The internal lock of this object lock.
+  ///
   mvm::Lock *lock;
-  JavaCond* varcond;
 
-  virtual void print(mvm::PrintBuffer* buf) const;
-  virtual void TRACER;
-  virtual void destroyer(size_t sz);
+  /// varcond - The condition variable for wait, notify and notifyAll calls.
+  ///
+  JavaCond* varcond;
 
+  /// allocate - Allocates a lock object. Only the internal lock is allocated.
+  ///
   static LockObj* allocate();
+  
+  /// myLock - Returns the lock object of this object, allocating it if
+  /// non-existant. This uses the big lock to make the object lock unique.
+  ///
   static LockObj* myLock(JavaObject* obj);
 
+  /// aquire - Acquires the lock.
+  ///
   void aquire();
+
+  /// release - Releases the lock.
+  ///
   void release();
+
+  /// owner - Returns true if the curren thread is the owner of this lock.
   bool owner();
+  
+  /// getCond - Returns the conditation variable of this lock, allocating it
+  /// if non-existant.
+  ///
+  JavaCond* getCond() {
+    if (!varcond) varcond = new JavaCond();
+    return varcond;
+  }
+  
+  virtual void print(mvm::PrintBuffer* buf) const;
+  virtual void TRACER;
+  virtual void destroyer(size_t sz);
 };
 
+
+/// JavaObject - This class represents a Java object.
+///
 class JavaObject : public mvm::Object {
+private:
+  
+  /// waitIntern - internal wait on a monitor
+  ///
+  void waitIntern(struct timeval *info, bool timed);
+
 public:
   static VirtualTable* VT;
+
+  /// classOf - The class of this object.
+  ///
   CommonClass* classOf;
-  LockObj* lockObj;
 
-  static mvm::Lock* globalLock;
-  
-  virtual void print(mvm::PrintBuffer* buf) const;
-  virtual void TRACER;
+  /// lockObj - The monitor of this object. Most of the time null.
+  ///
+  LockObj* lockObj;
   
-  void waitIntern(struct timeval *info, bool timed);
+  /// globalLock - The global lock to allocate monitors.
+  ///
+  static mvm::Lock* globalLock;
+   
+  /// wait - Java wait. Makes the current thread waiting on a monitor.
+  ///
   void wait();
+
+  /// timedWait - Java timed wait. Makes the current thread waiting on a
+  /// monitor for the given amount of time.
+  ///
   void timedWait(struct timeval &info);
+  
+  /// notify - Java notify. Notifies a thread from the availability of the
+  /// monitor.
+  ///
   void notify();
+  
+  /// notifyAll - Java notifyAll. Notifies all threads from the availability of
+  /// the monitor.
+  ///
   void notifyAll();
+  
+  /// initialise - Initialises the object.
+  ///
   void initialise(CommonClass* cl) {
     this->classOf = cl; 
     this->lockObj = 0;
   }
 
+  /// instanceOfString - Is this object's class of type the given name?
+  ///
   bool instanceOfString(const UTF8* name) {
     if (!this) return false;
     else return this->classOf->isOfTypeName(name);
   }
 
+  /// instanceOf - Is this object's class of type the given class?
+  ///
   bool instanceOf(CommonClass* cl) {
     if (!this) return false;
     else return this->classOf->isAssignableFrom(cl);
@@ -95,6 +176,9 @@
     if (obj == 0) JavaThread::get()->isolate->nullPointerException("");
 #endif
   
+  virtual void print(mvm::PrintBuffer* buf) const;
+  virtual void TRACER;
+  
 };
 
 





More information about the llvm-commits mailing list