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*1024*1024, -1, null, -1);
36 * Create a `basic' VM (i.e. 1 core, 1GB of RAM, other values are not taken into account).
38 public VM(Host host, String name, int nCore, long ramSize,
39 long netCap, String diskPath, long diskSize){
42 this.currentHost = host;
43 create(host, name, nCore, ramSize, netCap, diskPath, diskSize);
47 private static void addVM(VM vm){
53 vmsN = new VM[vms.length+1];
55 for (i=0; i<vmsN.length-1 ; i ++){
61 public static VM[] all(){
64 public static VM getVMByName(String name){
65 for (int i=0 ; i < vms.length ; i++){
66 if (vms[i].getName().equals(name))
71 protected void finalize() {
76 /* JNI / Native code */
77 /* get/set property methods are inherited from the Host class. */
79 /** Returns whether the given VM is currently suspended
81 public native int isCreated();
83 /** Returns whether the given VM is currently running
85 public native int isRunning();
87 /** Returns whether the given VM is currently running
89 public native int isMigrating();
91 /** Returns whether the given VM is currently suspended
93 public native int isSuspended();
95 /** Returns whether the given VM is currently saving
97 public native int isSaving();
99 /** Returns whether the given VM is currently saved
101 public native int isSaved();
103 /** Returns whether the given VM is currently restoring its state
105 public native boolean isRestoring();
108 * Natively implemented method create the VM.
109 * @param nCore, number of core
110 * @param ramSize, size of the RAM that should be allocated
111 * @param netCap (not used for the moment)
112 * @param diskPath (not used for the moment)
113 * @param diskSize (not used for the moment)
115 private native void create(Host host, String name, int nCore, long ramSize,
116 long netCap, String diskPath, long diskSize);
121 public native void start();
125 * Immediately kills all processes within the given VM. Any memory that they allocated will be leaked.
126 * No extra delay occurs. If you want to simulate this too, you want to use a MSG_process_sleep() or something
128 public native void shutdown();
131 * Invoke native migration routine
133 public native void internalmig(Host destination);
136 /** Change the host on which all processes are running
137 * (pre-copy is implemented)
139 public void migrate(Host destination){
140 // String[] argsRx = new String[5];
141 // argsRx[1] = this.getName();
142 // argsRx[2] = this.currentHost.getName();
143 // argsRx[3] = destination.getName();
144 // argsRx[0] = "__pr_mig_rx:"+argsRx[1]+"("+argsRx[2]+"-"+argsRx[3]+")";
145 // argsRx[4] = null; // TODO: Why ?
147 // //Process rx = new Process(destination, argsRx[0], argsRx );
149 // String[] argsTx = new String[5];
150 // argsTx[1] = this.getName();
151 // argsTx[2] = this.currentHost.getName();
152 // argsTx[3] = destination.getName();
153 // argsTx[0] = "__pr_mig_tx:"+argsTx[1]+"("+argsTx[2]+"-"+argsTx[3]+")";
154 // argsTx[4] = null; // TODO: Why ?
156 // //Process tx = new Process(this.currentHost, argsTx[0], argsRx );
158 this.internalmig(destination);
161 /** Immediately suspend the execution of all processes within the given VM
163 * No suspension cost occurs. If you want to simulate this too, you want to
164 * use a \ref File.write() before or after, depending on the exact semantic
165 * of VM suspend to you.
167 public native void suspend();
169 /** Immediately resumes the execution of all processes within the given VM
171 * No resume cost occurs. If you want to simulate this too, you want to
172 * use a \ref File.read() before or after, depending on the exact semantic
173 * of VM resume to you.
175 public native void resume();
177 /** Immediately suspend the execution of all processes within the given VM
178 * and save its state on the persistent HDD
179 * Not yet implemented (for the moment it behaves like suspend)
180 * No suspension cost occurs. If you want to simulate this too, you want to
181 * use a \ref File.write() before or after, depending on the exact semantic
182 * of VM suspend to you.
184 public native void save();
186 /** Immediately resumes the execution of all processes previously saved
187 * within the given VM
188 * Not yet implemented (for the moment it behaves like resume)
190 * No resume cost occurs. If you want to simulate this too, you want to
191 * use a \ref File.read() before or after, depending on the exact semantic
192 * of VM resume to you.
194 public native void restore();
200 public native void destroy();
205 * Class initializer, to initialize various JNI stuff
207 public static native void nativeInit();