2 * JNI interface to virtual machine in Simgrid
4 * Copyright 2006-2012 The SimGrid Team.
7 * This program is free software; you can redistribute
8 * it and/or modify it under the terms of the license
9 * (GNU LGPL) which comes with this package.
11 package org.simgrid.msg;
13 import org.simgrid.msg.Host;
14 import org.simgrid.msg.Process;
16 public class VM extends Host{
17 // Please note that we are not declaring a new bind variable
18 //(the bind variable has been inherited from the super class Host)
20 /* Static functions */
21 // GetByName is inherited from the super class Host
24 private static VM[] vms=null;
25 private Host currentHost;
27 /* Constructors / destructors */
29 * Create a `basic' VM (i.e. 1 core, 1GB of RAM, other values are not taken into account).
31 public VM(Host host, String name) {
32 this(host,name,1,1024, -1, null, -1,0 , 0);
37 * @param host, Host node
38 * @param name, name of the machine
39 * @param nCore, number of core
40 * @param ramSize, size of the RAM that should be allocated (in MBytes)
41 * @param netCap (not used for the moment)
42 * @param diskPath (not used for the moment)
43 * @param diskSize (not used for the moment)
44 * @param dpRate (dirty page rate MB/flop, if you don't know put zero ;))
45 * @param migNetSpeed (network bandwith allocated for migrations in MB/s, if you don't know put zero ;))
48 public VM(Host host, String name, int nCore, long ramSize,
49 long netCap, String diskPath, long diskSize, long dpRate,long migNetSpeed){
52 this.currentHost = host;
53 create(host, name, nCore, ramSize, netCap, diskPath, diskSize, dpRate, migNetSpeed);
57 private static void addVM(VM vm){
63 vmsN = new VM[vms.length+1];
65 for (i=0; i<vmsN.length-1 ; i ++){
71 public static VM[] all(){
74 public static VM getVMByName(String name){
75 for (int i=0 ; i < vms.length ; i++){
76 if (vms[i].getName().equals(name))
81 protected void finalize() {
86 /* JNI / Native code */
87 /* get/set property methods are inherited from the Host class. */
89 /** Returns whether the given VM is currently suspended
91 public native int isCreated();
93 /** Returns whether the given VM is currently running
95 public native int isRunning();
97 /** Returns whether the given VM is currently running
99 public native int isMigrating();
101 /** Returns whether the given VM is currently suspended
103 public native int isSuspended();
105 /** Returns whether the given VM is currently saving
107 public native int isSaving();
109 /** Returns whether the given VM is currently saved
111 public native int isSaved();
113 /** Returns whether the given VM is currently restoring its state
115 public native boolean isRestoring();
118 * Natively implemented method create the VM.
119 * @param nCore, number of core
120 * @param ramSize, size of the RAM that should be allocated (in MB)
121 * @param netCap (not used for the moment)
122 * @param diskPath (not used for the moment)
123 * @param diskSize (not used for the moment)
124 * @param dpRate (dirty page rate in MB/flop, if you don't know put zero ;))
125 * @param migNetSpeed (network bandwith allocated for migrations in MB/s, if you don't know put zero ;))
127 private native void create(Host host, String name, int nCore, long ramSize,
128 long netCap, String diskPath, long diskSize, long dpRate, long migNetSpeed);
133 public native void start();
137 * Immediately kills all processes within the given VM. Any memory that they allocated will be leaked.
138 * No extra delay occurs. If you want to simulate this too, you want to use a MSG_process_sleep() or something
140 public native void shutdown();
143 * Invoke native migration routine
145 public native void internalmig(Host destination);
148 /** Change the host on which all processes are running
149 * (pre-copy is implemented)
151 public void migrate(Host destination){
152 // String[] argsRx = new String[5];
153 // argsRx[1] = this.getName();
154 // argsRx[2] = this.currentHost.getName();
155 // argsRx[3] = destination.getName();
156 // argsRx[0] = "__pr_mig_rx:"+argsRx[1]+"("+argsRx[2]+"-"+argsRx[3]+")";
157 // argsRx[4] = null; // TODO: Why ?
159 // //Process rx = new Process(destination, argsRx[0], argsRx );
161 // String[] argsTx = new String[5];
162 // argsTx[1] = this.getName();
163 // argsTx[2] = this.currentHost.getName();
164 // argsTx[3] = destination.getName();
165 // argsTx[0] = "__pr_mig_tx:"+argsTx[1]+"("+argsTx[2]+"-"+argsTx[3]+")";
166 // argsTx[4] = null; // TODO: Why ?
168 // //Process tx = new Process(this.currentHost, argsTx[0], argsRx );
170 this.internalmig(destination);
173 /** Immediately suspend the execution of all processes within the given VM
175 * No suspension cost occurs. If you want to simulate this too, you want to
176 * use a \ref File.write() before or after, depending on the exact semantic
177 * of VM suspend to you.
179 public native void suspend();
181 /** Immediately resumes the execution of all processes within the given VM
183 * No resume cost occurs. If you want to simulate this too, you want to
184 * use a \ref File.read() before or after, depending on the exact semantic
185 * of VM resume to you.
187 public native void resume();
189 /** Immediately suspend the execution of all processes within the given VM
190 * and save its state on the persistent HDD
191 * Not yet implemented (for the moment it behaves like suspend)
192 * No suspension cost occurs. If you want to simulate this too, you want to
193 * use a \ref File.write() before or after, depending on the exact semantic
194 * of VM suspend to you.
196 public native void save();
198 /** Immediately resumes the execution of all processes previously saved
199 * within the given VM
200 * Not yet implemented (for the moment it behaves like resume)
202 * No resume cost occurs. If you want to simulate this too, you want to
203 * use a \ref File.read() before or after, depending on the exact semantic
204 * of VM resume to you.
206 public native void restore();
212 public native void destroy();
217 * Class initializer, to initialize various JNI stuff
219 public static native void nativeInit();