[vmkit-commits] [vmkit] r60567 - in /vmkit/trunk: include/mvm/VirtualMachine.h lib/JnJVM/VMCore/BundleTermination.cpp lib/JnJVM/VMCore/Jnjvm.cpp lib/JnJVM/VMCore/Jnjvm.h lib/Mvm/GCMmap2/gccollector.cpp lib/Mvm/GCMmap2/gccollector.h lib/Mvm/GCMmap2/gcthread.h

Nicolas Geoffray nicolas.geoffray at lip6.fr
Thu Dec 4 16:02:42 PST 2008


Author: geoffray
Date: Thu Dec  4 18:02:42 2008
New Revision: 60567

URL: http://llvm.org/viewvc/llvm-project?rev=60567&view=rev
Log:
[SERVICE] Better support for resource policies.


Modified:
    vmkit/trunk/include/mvm/VirtualMachine.h
    vmkit/trunk/lib/JnJVM/VMCore/BundleTermination.cpp
    vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp
    vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h
    vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp
    vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h
    vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h

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

==============================================================================
--- vmkit/trunk/include/mvm/VirtualMachine.h (original)
+++ vmkit/trunk/include/mvm/VirtualMachine.h Thu Dec  4 18:02:42 2008
@@ -26,6 +26,19 @@
 /// defines what a VM should be.
 ///
 class VirtualMachine : public mvm::Object {
+protected:
+
+  VirtualMachine() {
+#ifdef SERVICE
+    memoryLimit = ~0;
+    executionLimit = ~0;
+    GCLimit = ~0;
+    threadLimit = ~0;
+    parent = this;
+    status = 1;
+    _since_last_collection = 4*1024*1024;
+#endif
+  }
 public:
   
   /// runApplication - Run an application. The application name is in
@@ -50,7 +63,6 @@
 #endif
 
 #ifdef SERVICE
-  size_t status;
   uint64_t memoryUsed;
   uint64_t gcTriggered;
   uint64_t executionTime;
@@ -60,6 +72,12 @@
 
   uint64_t memoryLimit;
   uint64_t executionLimit;
+  uint64_t threadLimit;
+  uint64_t GCLimit;
+
+  int _since_last_collection;
+  VirtualMachine* parent;
+  uint32 status; 
 #endif
 
   mvm::Allocator gcAllocator;

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/BundleTermination.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/BundleTermination.cpp Thu Dec  4 18:02:42 2008
@@ -117,21 +117,24 @@
   // I have to do it too!
   terminationHandler(0);
    
-  llvm::TargetJITInfo& TJI = ((llvm::JIT*)mvm::MvmModule::executionEngine)->getJITInfo();
-  for (ClassMap::iterator i = bundle->getClasses()->map.begin(), e = bundle->getClasses()->map.end();
-       i!= e; ++i) {
+  llvm::TargetJITInfo& TJI = 
+    ((llvm::JIT*)mvm::MvmModule::executionEngine)->getJITInfo();
+  for (ClassMap::iterator i = bundle->getClasses()->map.begin(), 
+       e = bundle->getClasses()->map.end(); i!= e; ++i) {
     Class* cl = i->second->asClass();
 
     if (cl) {
       for (uint32 i = 0; i < cl->nbVirtualMethods; ++i) {
         if (cl->virtualMethods[i].code) {
-          TJI.replaceMachineCodeForFunction(cl->virtualMethods[i].code, (void*)(uintptr_t)throwStoppedBundleException);
+          TJI.replaceMachineCodeForFunction(cl->virtualMethods[i].code,
+                              (void*)(uintptr_t)throwStoppedBundleException);
         }
       }
     
       for (uint32 i = 0; i < cl->nbStaticMethods; ++i) {
         if (cl->staticMethods[i].code) {
-          TJI.replaceMachineCodeForFunction(cl->staticMethods[i].code, (void*)(uintptr_t)throwStoppedBundleException);
+          TJI.replaceMachineCodeForFunction(cl->staticMethods[i].code, 
+                              (void*)(uintptr_t)throwStoppedBundleException);
         }
       }
     }

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.cpp Thu Dec  4 18:02:42 2008
@@ -976,7 +976,7 @@
   }
 }
 
-Jnjvm::Jnjvm(JnjvmBootstrapLoader* loader) {
+Jnjvm::Jnjvm(JnjvmBootstrapLoader* loader) : VirtualMachine() {
 
   classpath = getenv("CLASSPATH");
   if (!classpath) classpath = ".";
@@ -1003,13 +1003,6 @@
   IsolateLock.unlock();
 #endif
 
-#ifdef SERVICE
-  memoryLimit = ~0;
-  executionLimit = ~0;
-  parent = this;
-  status = 1;
-#endif
-
 }
 
 Jnjvm::~Jnjvm() {

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

==============================================================================
--- vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h (original)
+++ vmkit/trunk/lib/JnJVM/VMCore/Jnjvm.h Thu Dec  4 18:02:42 2008
@@ -334,8 +334,6 @@
 
 #ifdef SERVICE
   virtual void stopService();
-  Jnjvm* parent;
-  uint32 status;
 #endif
 
 };

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

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gccollector.cpp Thu Dec  4 18:02:42 2008
@@ -39,7 +39,11 @@
 void GCCollector::do_collect() {
   //printf("----- do collect -----\n");
   GCChunkNode  *cur;
+#ifdef SERVICE
+  mvm::Thread::get()->MyVM->_since_last_collection = _collect_freq_auto;
+#else
   _since_last_collection = _collect_freq_auto;
+#endif
 
   current_mark++;
 

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

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gccollector.h Thu Dec  4 18:02:42 2008
@@ -135,7 +135,12 @@
 
   static inline void maybeCollect() {
     if(_enable_auto && 
-       (_since_last_collection <= (_collect_freq_auto - _collect_freq_maybe)))
+#ifdef SERVICE
+       (mvm::Thread::get()->MyVM->_since_last_collection <= (_collect_freq_auto - _collect_freq_maybe))
+#else
+       (_since_last_collection <= (_collect_freq_auto - _collect_freq_maybe))
+#endif
+      )
       collect(); 
   }
 
@@ -147,30 +152,40 @@
     return res;
 #else
     lock();
-    
-    _since_last_collection -= n;
-    if(_enable_auto && (_since_last_collection <= 0)) {
-#ifdef SERVICE
-      if (threads->get_nb_threads()) {
-        mvm::Thread::get()->MyVM->gcTriggered++;
-      }
-#endif
-      collect_unprotect();
-    }
-   
+
 #ifdef SERVICE
     if (threads->get_nb_threads()) {
       VirtualMachine* vm = mvm::Thread::get()->MyVM;
+      vm->_since_last_collection -= n;
+      if (_enable_auto && (vm->_since_last_collection <= 0)) {
+        vm->gcTriggered++;
+        if (vm->gcTriggered > vm->GCLimit) {
+          vm->_since_last_collection += n;
+          unlock();
+          vm->stopService();
+          return 0;
+        }
+        collect_unprotect();
+      }
+      
       if (vm->memoryUsed + n > vm->memoryLimit) {
-        _since_last_collection += n;
+        vm->_since_last_collection += n;
         unlock();
         vm->stopService();
         return 0;
       }
+    } else {
+#endif
+    
+    _since_last_collection -= n;
+    if(_enable_auto && (_since_last_collection <= 0)) {
+      collect_unprotect();
+    }
+#ifdef SERVICE
     }
 #endif
-
     register GCChunkNode *header = allocator->alloc_chunk(n, 1, current_mark & 1);
+
 #ifdef SERVICE
     if (threads->get_nb_threads()) {
       VirtualMachine* vm = mvm::Thread::get()->MyVM;
@@ -204,27 +219,36 @@
       gcfatal("%p isn't a avalid object", ptr);
 
     size_t      old_sz = node->nbb();
-    
-    _since_last_collection -= (n - old_sz);
-
-    if(_enable_auto && (_since_last_collection <= 0)) {
-#ifdef SERVICE
-      if (threads->get_nb_threads()) {
-        mvm::Thread::get()->MyVM->gcTriggered++;
-      }
-#endif
-      collect_unprotect();
-    }
-
 #ifdef SERVICE
     if (threads->get_nb_threads()) {
       VirtualMachine* vm = mvm::Thread::get()->MyVM;
+      vm->_since_last_collection -= (n - old_sz);
+      if (_enable_auto && (vm->_since_last_collection <= 0)) {
+        if (vm->gcTriggered + 1 > vm->GCLimit) {
+          unlock();
+          vm->stopService();
+          return 0;
+        }
+        vm->gcTriggered++;
+        collect_unprotect();
+      }
+      
       if (vm->memoryUsed + (n - old_sz) > vm->memoryLimit) {
-        _since_last_collection += (n - old_sz);
+        vm->_since_last_collection += (n - old_sz);
         unlock();
         vm->stopService();
         return 0;
       }
+    } else {
+#endif
+    
+    _since_last_collection -= (n - old_sz);
+
+    if(_enable_auto && (_since_last_collection <= 0)) {
+      collect_unprotect();
+    }
+
+#ifdef SERVICE
     }
 #endif
 

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

==============================================================================
--- vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h (original)
+++ vmkit/trunk/lib/Mvm/GCMmap2/gcthread.h Thu Dec  4 18:02:42 2008
@@ -125,14 +125,18 @@
 
   inline void inject(mvm::Thread* th) { 
     lock(); 
+#ifdef SERVICE
+    if (th->MyVM->numThreads + 1 > th->MyVM->threadLimit) {
+      unlock();
+      th->MyVM->stopService();
+    }
+    th->MyVM->numThreads++;
+#endif
     if (base)
       th->append(base);
     else
       base = th;
     _nb_threads++;
-#ifdef SERVICE
-    th->MyVM->numThreads++;
-#endif
     unlock();
   }
 };





More information about the vmkit-commits mailing list