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);
153 /** Change the host on which all processes are running
154 * (pre-copy is implemented)
156 public void migrate(Host destination){
157 this.internalmig(destination);
158 // TODO we should test whether the migration has been correctly finalized.
159 // If and only if it is ok, then we should change the currentHost value.
160 this.currentHost = destination;
163 /** Immediately suspend the execution of all processes within the given VM
165 * No suspension cost occurs. If you want to simulate this too, you want to
166 * use a \ref File.write() before or after, depending on the exact semantic
167 * of VM suspend to you.
169 public native void suspend();
171 /** Immediately resumes the execution of all processes within the given VM
173 * No resume cost occurs. If you want to simulate this too, you want to
174 * use a \ref File.read() before or after, depending on the exact semantic
175 * of VM resume to you.
177 public native void resume();
179 /** Immediately suspend the execution of all processes within the given VM
180 * and save its state on the persistent HDD
181 * Not yet implemented (for the moment it behaves like suspend)
182 * No suspension cost occurs. If you want to simulate this too, you want to
183 * use a \ref File.write() before or after, depending on the exact semantic
184 * of VM suspend to you.
186 public native void save();
188 /** Immediately resumes the execution of all processes previously saved
189 * within the given VM
190 * Not yet implemented (for the moment it behaves like resume)
192 * No resume cost occurs. If you want to simulate this too, you want to
193 * use a \ref File.read() before or after, depending on the exact semantic
194 * of VM resume to you.
196 public native void restore();
202 public native void destroy();
207 * Class initializer, to initialize various JNI stuff
209 public static native void nativeInit();