[vmkit-commits] [vmkit] r120710 - in /vmkit/branches/multi-vm: include/mvm/VMKit.h include/mvm/VirtualMachine.h lib/Mvm/Runtime/VMKit.cpp lib/Mvm/Runtime/VirtualMachine.cpp

Gael Thomas gael.thomas at lip6.fr
Thu Dec 2 08:40:26 PST 2010


Author: gthomas
Date: Thu Dec  2 10:40:26 2010
New Revision: 120710

URL: http://llvm.org/viewvc/llvm-project?rev=120710&view=rev
Log:
register all the vms inside vmkit

Added:
    vmkit/branches/multi-vm/lib/Mvm/Runtime/VMKit.cpp
    vmkit/branches/multi-vm/lib/Mvm/Runtime/VirtualMachine.cpp
Modified:
    vmkit/branches/multi-vm/include/mvm/VMKit.h
    vmkit/branches/multi-vm/include/mvm/VirtualMachine.h

Modified: vmkit/branches/multi-vm/include/mvm/VMKit.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/multi-vm/include/mvm/VMKit.h?rev=120710&r1=120709&r2=120710&view=diff
==============================================================================
--- vmkit/branches/multi-vm/include/mvm/VMKit.h (original)
+++ vmkit/branches/multi-vm/include/mvm/VMKit.h Thu Dec  2 10:40:26 2010
@@ -1,8 +1,10 @@
 #ifndef _VMKIT_H_
 #define _VMKIT_H_
 
+#include <vector>
 #include "mvm/Allocator.h"
 #include "mvm/Threads/CollectionRV.h"
+#include "mvm/VirtualMachine.h"
 
 namespace mvm {
 
@@ -13,6 +15,14 @@
 
   VMKit(mvm::BumpPtrAllocator &Alloc) : allocator(Alloc) {
 	}
+	/// ------------------------------------------------- ///
+	/// ---             vm managment                  --- ///
+	/// ------------------------------------------------- ///
+	mvm::SpinLock                lockvms;  // lock for vms
+	std::vector<VirtualMachine*> vms;      // array of vms
+
+	size_t addVM(VirtualMachine* vm);
+	void   removeVM(size_t id);
 
 	/// ------------------------------------------------- ///
 	/// ---             thread managment              --- ///

Modified: vmkit/branches/multi-vm/include/mvm/VirtualMachine.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/multi-vm/include/mvm/VirtualMachine.h?rev=120710&r1=120709&r2=120710&view=diff
==============================================================================
--- vmkit/branches/multi-vm/include/mvm/VirtualMachine.h (original)
+++ vmkit/branches/multi-vm/include/mvm/VirtualMachine.h Thu Dec  2 10:40:26 2010
@@ -53,16 +53,15 @@
 /// defines what a VM should be.
 ///
 class VirtualMachine : public mvm::PermanentObject {
-protected:
-  VirtualMachine(mvm::BumpPtrAllocator &Alloc, mvm::VMKit* vmk) :
-		  allocator(Alloc) {
-		vmkit = vmk;
-  }
+private:
+	friend class VMKit;
+	VirtualMachine(mvm::BumpPtrAllocator &Alloc) : allocator(Alloc) {}
 
-  virtual ~VirtualMachine() {
-  }
+protected:
+  VirtualMachine(mvm::BumpPtrAllocator &Alloc, mvm::VMKit* vmk);
 
 public:
+  virtual ~VirtualMachine();
 
   /// allocator - Bump pointer allocator to allocate permanent memory
   /// related to this VM.
@@ -73,9 +72,8 @@
 	///
 	mvm::VMKit* vmkit;
 
-//===----------------------------------------------------------------------===//
-// (1) Thread-related methods.
-//===----------------------------------------------------------------------===//
+	/// vmID - id of the vm
+	size_t vmID;
 
 //===----------------------------------------------------------------------===//
 // (2) GC-related methods.
@@ -120,7 +118,7 @@
 
   /// getObjectSize - Get the size of this object. Used by copying collectors.
   ///
-  virtual size_t getObjectSize(gc* object) = 0;
+  virtual size_t getObjectSize(gc* object) { abort(); }
 
   /// getObjectTypeName - Get the type of this object. Used by the GC for
   /// debugging purposes.
@@ -145,10 +143,10 @@
 
   /// runApplication - Run an application. The application name is in
   /// the arguments, hence it is the virtual machine's job to parse them.
-  virtual void runApplication(int argc, char** argv) = 0;
+  virtual void runApplication(int argc, char** argv) { abort(); }
   
   /// waitForExit - Wait until the virtual machine stops its execution.
-  virtual void waitForExit() = 0;
+  virtual void waitForExit() { abort(); }
 };
 
 } // end namespace mvm

Added: vmkit/branches/multi-vm/lib/Mvm/Runtime/VMKit.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/multi-vm/lib/Mvm/Runtime/VMKit.cpp?rev=120710&view=auto
==============================================================================
--- vmkit/branches/multi-vm/lib/Mvm/Runtime/VMKit.cpp (added)
+++ vmkit/branches/multi-vm/lib/Mvm/Runtime/VMKit.cpp Thu Dec  2 10:40:26 2010
@@ -0,0 +1,21 @@
+#include "mvm/VMKit.h"
+#include "mvm/VirtualMachine.h"
+
+using namespace mvm;
+
+size_t VMKit::addVM(VirtualMachine* vm) {
+	lockvms.lock();
+	for(size_t i=0; i<vms.size(); i++)
+		if(!vms[i]) {
+			vms[i] = vm;
+			return i;
+		}
+	int res = vms.size();
+	vms.push_back(vm);
+	lockvms.unlock();
+	return res;
+}
+
+void VMKit::removeVM(size_t id) {
+	vms[id] = 0;
+}

Added: vmkit/branches/multi-vm/lib/Mvm/Runtime/VirtualMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/multi-vm/lib/Mvm/Runtime/VirtualMachine.cpp?rev=120710&view=auto
==============================================================================
--- vmkit/branches/multi-vm/lib/Mvm/Runtime/VirtualMachine.cpp (added)
+++ vmkit/branches/multi-vm/lib/Mvm/Runtime/VirtualMachine.cpp Thu Dec  2 10:40:26 2010
@@ -0,0 +1,13 @@
+#include "mvm/VirtualMachine.h"
+#include "mvm/VMKit.h"
+
+using namespace mvm;
+
+VirtualMachine::VirtualMachine(mvm::BumpPtrAllocator &Alloc, mvm::VMKit* vmk) :	allocator(Alloc) {
+	vmkit = vmk;
+	vmID = vmkit->addVM(this);
+}
+
+VirtualMachine::~VirtualMachine() {
+	vmkit->removeVM(vmID);
+}





More information about the vmkit-commits mailing list