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;
12 public class VM extends Host{
13 // Please note that we are not declaring a new bind variable
14 //(the bind variable has been inherited from the super class Host)
16 /* Static functions */
17 // GetByName is inherited from the super class Host
20 private static VM[] vms=null;
21 private Host currentHost;
23 /* Constructors / destructors */
25 * Create a `basic' VM (i.e. 1 core, 1GB of RAM, other values are not taken into account).
27 public VM(Host host, String name) {
28 this(host,name,1,1024, -1, null, -1,0 , 0);
33 * @param host Host node
34 * @param name name of the machine
35 * @param nCore number of core
36 * @param ramSize size of the RAM that should be allocated (in MBytes)
37 * @param netCap (not used for the moment)
38 * @param diskPath (not used for the moment)
39 * @param diskSize (not used for the moment)
40 * @param migNetSpeed (network bandwith allocated for migrations in MB/s, if you don't know put zero ;))
41 * @param dpIntensity (dirty page percentage according to migNetSpeed, [0-100], if you don't know put zero ;))
43 public VM(Host host, String name, int nCore, int ramSize,
44 int netCap, String diskPath, int diskSize, int migNetSpeed, int dpIntensity){
47 this.currentHost = host;
48 create(host, name, nCore, ramSize, netCap, diskPath, diskSize, migNetSpeed, dpIntensity);
52 private static void addVM(VM vm){
58 vmsN = new VM[vms.length+1];
60 for (i=0; i<vmsN.length-1 ; i ++){
66 public static VM[] all(){
69 public static VM getVMByName(String name){
70 for (int i=0 ; i < vms.length ; i++){
71 if (vms[i].getName().equals(name))
77 public void finalize() {
80 } catch (Throwable e) {
84 private native void nativeFinalize();
87 /* JNI / Native code */
89 /* get/set property methods are inherited from the Host class. */
91 /** Returns whether the given VM is currently suspended
93 public native int isCreated();
95 /** Returns whether the given VM is currently running
97 public native int isRunning();
99 /** Returns whether the given VM is currently running
101 public native int isMigrating();
103 /** Returns whether the given VM is currently suspended
105 public native int isSuspended();
107 /** Returns whether the given VM is currently saving
109 public native int isSaving();
111 /** Returns whether the given VM is currently saved
113 public native int isSaved();
115 /** Returns whether the given VM is currently restoring its state
117 public native boolean isRestoring();
120 * Natively implemented method create the VM.
121 * @param nCore number of core
122 * @param ramSize size of the RAM that should be allocated (in MB)
123 * @param netCap (not used for the moment)
124 * @param diskPath (not used for the moment)
125 * @param diskSize (not used for the moment)
126 * @param migNetSpeed (network bandwith allocated for migrations in MB/s, if you don't know put zero ;))
127 * @param dpIntensity (dirty page intensity, a percentage of migNetSpeed [0-100], if you don't know put zero ;))
129 private native void create(Host host, String name, int nCore, int ramSize,
130 int netCap, String diskPath, int diskSize, int migNetSpeed, int dpIntensity);
134 * Set a CPU bound for a given VM.
135 * @param bound in flops/s
137 public native void setBound(double bound);
142 public native void start();
146 * Immediately kills all processes within the given VM. Any memory that they allocated will be leaked.
147 * No extra delay occurs. If you want to simulate this too, you want to use a MSG_process_sleep() or something
149 public native void shutdown();
152 * Invoke native migration routine
154 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);
158 /** Change the host on which all processes are running
159 * (pre-copy is implemented)
161 public void migrate(Host destination) throws HostFailureException{
163 this.internalmig(destination);
164 } catch (Exception e){
165 Msg.info("Migration of VM "+this.getName()+" to "+destination.getName()+" is impossible ("+e.getMessage()+")");
166 throw new HostFailureException();
168 // If the migration correcly returned, then we should change the currentHost value.
169 this.currentHost = destination;
172 /** Immediately suspend the execution of all processes within the given VM
174 * No suspension cost occurs. If you want to simulate this too, you want to
175 * use a \ref File.write() before or after, depending on the exact semantic
176 * of VM suspend to you.
178 public native void suspend();
180 /** Immediately resumes the execution of all processes within the given VM
182 * No resume cost occurs. If you want to simulate this too, you want to
183 * use a \ref File.read() before or after, depending on the exact semantic
184 * of VM resume to you.
186 public native void resume();
188 /** Immediately suspend the execution of all processes within the given VM
189 * and save its state on the persistent HDD
190 * Not yet implemented (for the moment it behaves like suspend)
191 * No suspension cost occurs. If you want to simulate this too, you want to
192 * use a \ref File.write() before or after, depending on the exact semantic
193 * of VM suspend to you.
195 public native void save();
197 /** Immediately resumes the execution of all processes previously saved
198 * within the given VM
199 * Not yet implemented (for the moment it behaves like resume)
201 * No resume cost occurs. If you want to simulate this too, you want to
202 * use a \ref File.read() before or after, depending on the exact semantic
203 * of VM resume to you.
205 public native void restore();
209 * Class initializer, to initialize various JNI stuff
211 public static native void nativeInit();