Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #244 from Takishipp/actor-yield
[simgrid.git] / src / bindings / java / org / simgrid / msg / VM.java
index 867eed8..cdd7cd7 100644 (file)
@@ -1,55 +1,71 @@
-/* JNI interface to virtual machine in Simgrid */
+/* Java bindings of the s4u::VirtualMachine */
 
-/* Copyright (c) 2006-2014. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2006-2017. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 package org.simgrid.msg;
-import java.util.ArrayList;
 
 public class VM extends Host {
        // No need to declare a new bind variable: we use the one inherited from the super class Host
 
-       /* Static functions */ 
-
-       private static ArrayList<VM> vms= new ArrayList<>();
        private Host currentHost; 
+       private int coreAmount = 1;
 
-       /** Create a `basic' VM (i.e. 1GB of RAM, other values are not taken into account). */
+       /**
+        * Create a `basic' VM : 1 core and 1GB of RAM.
+        * @param host Host node
+        * @param name name of the machine
+        */     
        public VM(Host host, String name) {
-               this(host,name,1024, 0, 0);
+               this(host,name, /*coreAmount*/1, 1024, 0, 0);
+       }
+
+       /**
+        * Create a VM without useless values (for humans)
+        * @param host Host node
+        * @param name name of the machine
+        * @param coreAmount the amount of cores of the VM
+        */     
+       public VM(Host host, String name, int coreAmount) {
+               this(host,name, coreAmount, 1024, 0, 0);
+       }
+
+       /**
+        * Create a VM with 1 core
+        * @param host Host node
+        * @param name name of the machine
+        * @param ramSize size of the RAM that should be allocated (in MBytes)
+        * @param migNetSpeed (network bandwith allocated for migrations in MB/s, if you don't know put zero ;))
+        * @param dpIntensity (dirty page percentage according to migNetSpeed, [0-100], if you don't know put zero ;))
+        */     
+       public VM(Host host, String name, int ramSize, int migNetSpeed, int dpIntensity){
+               this(host, name, /*coreAmount*/1, ramSize, migNetSpeed, dpIntensity);
        }
 
        /**
         * Create a VM
         * @param host Host node
         * @param name name of the machine
+        * @param coreAmount the amount of cores of the VM
         * @param ramSize size of the RAM that should be allocated (in MBytes)
         * @param migNetSpeed (network bandwith allocated for migrations in MB/s, if you don't know put zero ;))
         * @param dpIntensity (dirty page percentage according to migNetSpeed, [0-100], if you don't know put zero ;))
         */
-       public VM(Host host, String name, int ramSize, int migNetSpeed, int dpIntensity){
+       public VM(Host host, String name, int coreAmount, int ramSize, int migNetSpeed, int dpIntensity){
                super();
                super.name = name;
                this.currentHost = host; 
-               create(host, name, ramSize, migNetSpeed, dpIntensity);
-               vms.add(this);
+               this.coreAmount = coreAmount;
+               create(host, name, coreAmount, ramSize, migNetSpeed, dpIntensity);
        }
 
-       public static VM[] all(){
-               VM[] allvms = new VM[vms.size()];
-               vms.toArray(allvms);
-               return allvms;
-       }
+       /** Retrieve the list of all existing VMs */
+       public static native VM[] all();
 
-       public static VM getVMByName(String name){
-               for (VM vm : vms){
-                       if (vm.getName().equals(name))
-                               return vm;
-               }
-               return null; 
-       }
+       /** Retrieve a VM from its name */
+       public static native VM getVMByName(String name);
        
        /** Shutdown and unref the VM. 
         * 
@@ -61,14 +77,13 @@ public class VM extends Host {
         */
        public void destroy() {
                shutdown();
-///            vms.remove(this);
        }
 
        /* Make sure that the GC also destroys the C object */
        protected void finalize() throws Throwable {
                nativeFinalize();
        }
-       public native void nativeFinalize();
+       private native void nativeFinalize();
 
        /** Returns whether the given VM is currently suspended */      
        public native int isCreated();
@@ -82,13 +97,18 @@ public class VM extends Host {
        /** Returns whether the given VM is currently suspended */      
        public native int isSuspended();
 
+       /** Returns the amount of virtual CPUs provided */
+       public int getCoreAmount() {
+               return coreAmount;
+       }
+       
        /**
         * Natively implemented method create the VM.
         * @param ramSize size of the RAM that should be allocated (in MB)
         * @param migNetSpeed (network bandwith allocated for migrations in MB/s, if you don't know put zero ;))
         * @param dpIntensity (dirty page intensity, a percentage of migNetSpeed [0-100],  if you don't know put zero ;))
         */
-       private native void create(Host host, String name, int ramSize, int migNetSpeed, int dpIntensity);
+       private native void create(Host host, String name, int coreAmount, int ramSize, int migNetSpeed, int dpIntensity);
 
 
        /**
@@ -108,9 +128,6 @@ public class VM extends Host {
         */
        public native void shutdown();
 
-       /** native migration routine */
-       private native void nativeMigration(Host destination) throws Exception;
-
        /** Change the host on which all processes are running
         * (pre-copy is implemented)
         */     
@@ -124,6 +141,7 @@ public class VM extends Host {
                // If the migration correcly returned, then we should change the currentHost value. 
                this.currentHost = destination; 
        }
+       private native void nativeMigration(Host destination) throws MsgException;
 
        /** Immediately suspend the execution of all processes within the given VM
         *
@@ -142,7 +160,7 @@ public class VM extends Host {
        public native void resume();
 
        /**  Class initializer (for JNI), don't do it yourself */
-       public static native void nativeInit();
+       private static native void nativeInit();
        static {
                nativeInit();
        }