1 /* JNI interface to virtual machine in Simgrid */
3 /* Copyright (c) 2006-2014. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 package org.simgrid.msg;
11 import org.simgrid.msg.Host;
12 import org.simgrid.msg.Process;
14 public class VM extends Host{
15 // Please note that we are not declaring a new bind variable
16 //(the bind variable has been inherited from the super class Host)
18 /* Static functions */
19 // GetByName is inherited from the super class Host
22 private static VM[] vms=null;
23 private Host currentHost;
25 /* Constructors / destructors */
27 * Create a `basic' VM (i.e. 1 core, 1GB of RAM, other values are not taken into account).
29 public VM(Host host, String name) {
30 this(host,name,1,1024, -1, null, -1,0 , 0);
35 * @param host Host node
36 * @param name name of the machine
37 * @param nCore number of core
38 * @param ramSize size of the RAM that should be allocated (in MBytes)
39 * @param netCap (not used for the moment)
40 * @param diskPath (not used for the moment)
41 * @param diskSize (not used for the moment)
42 * @param migNetSpeed (network bandwith allocated for migrations in MB/s, if you don't know put zero ;))
43 * @param dpIntensity (dirty page percentage according to migNetSpeed, [0-100], if you don't know put zero ;))
45 public VM(Host host, String name, int nCore, int ramSize,
46 int netCap, String diskPath, int diskSize, int migNetSpeed, int dpIntensity){
49 this.currentHost = host;
50 create(host, name, nCore, ramSize, netCap, diskPath, diskSize, migNetSpeed, dpIntensity);
54 private static void addVM(VM vm){
60 vmsN = new VM[vms.length+1];
62 for (i=0; i<vmsN.length-1 ; i ++){
68 public static VM[] all(){
71 public static VM getVMByName(String name){
72 for (int i=0 ; i < vms.length ; i++){
73 if (vms[i].getName().equals(name))
78 protected void finalize() {
83 /* JNI / Native code */
85 /* get/set property methods are inherited from the Host class. */
87 /** Returns whether the given VM is currently suspended
89 public native int isCreated();
91 /** Returns whether the given VM is currently running
93 public native int isRunning();
95 /** Returns whether the given VM is currently running
97 public native int isMigrating();
99 /** Returns whether the given VM is currently suspended
101 public native int isSuspended();
103 /** Returns whether the given VM is currently saving
105 public native int isSaving();
107 /** Returns whether the given VM is currently saved
109 public native int isSaved();
111 /** Returns whether the given VM is currently restoring its state
113 public native boolean isRestoring();
116 * Natively implemented method create the VM.
117 * @param nCore number of core
118 * @param ramSize size of the RAM that should be allocated (in MB)
119 * @param netCap (not used for the moment)
120 * @param diskPath (not used for the moment)
121 * @param diskSize (not used for the moment)
122 * @param migNetSpeed (network bandwith allocated for migrations in MB/s, if you don't know put zero ;))
123 * @param dpIntensity (dirty page intensity, a percentage of migNetSpeed [0-100], if you don't know put zero ;))
125 private native void create(Host host, String name, int nCore, int ramSize,
126 int netCap, String diskPath, int diskSize, int migNetSpeed, int dpIntensity);
130 * Bound the VM to a certain % of its vcpu capability (e.g. 75% of vm.getSpeed())
131 * @param load percentage (between [0,100]
133 public native void setBound(int load);
138 public native void start();
142 * Immediately kills all processes within the given VM. Any memory that they allocated will be leaked.
143 * No extra delay occurs. If you want to simulate this too, you want to use a MSG_process_sleep() or something
145 public native void shutdown();
148 * Invoke native migration routine
150 public native void internalmig(Host destination) throws Exception; // TODO add throws DoubleMigrationException (i.e. when you call migrate on a VM that is already migrating);
154 /** Change the host on which all processes are running
155 * (pre-copy is implemented)
157 public void migrate(Host destination) throws HostFailureException{
159 Msg.info("Migrate begins");
160 this.internalmig(destination);
161 Msg.info("Migrate ends");
162 } catch (Exception e){
163 Msg.info("an exception occurs during the migration of VM "+this.getName());
164 throw new HostFailureException();
166 // If the migration correcly returned, then we should change the currentHost value.
167 this.currentHost = destination;
170 /** Immediately suspend the execution of all processes within the given VM
172 * No suspension cost occurs. If you want to simulate this too, you want to
173 * use a \ref File.write() before or after, depending on the exact semantic
174 * of VM suspend to you.
176 public native void suspend();
178 /** Immediately resumes the execution of all processes within the given VM
180 * No resume cost occurs. If you want to simulate this too, you want to
181 * use a \ref File.read() before or after, depending on the exact semantic
182 * of VM resume to you.
184 public native void resume();
186 /** Immediately suspend the execution of all processes within the given VM
187 * and save its state on the persistent HDD
188 * Not yet implemented (for the moment it behaves like suspend)
189 * No suspension cost occurs. If you want to simulate this too, you want to
190 * use a \ref File.write() before or after, depending on the exact semantic
191 * of VM suspend to you.
193 public native void save();
195 /** Immediately resumes the execution of all processes previously saved
196 * within the given VM
197 * Not yet implemented (for the moment it behaves like resume)
199 * No resume cost occurs. If you want to simulate this too, you want to
200 * use a \ref File.read() before or after, depending on the exact semantic
201 * of VM resume to you.
203 public native void restore();
209 public native void destroy();
214 * Class initializer, to initialize various JNI stuff
216 public static native void nativeInit();