Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
distinguish shutdown and destroy in Java VMs
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 24 Jan 2018 09:30:15 +0000 (10:30 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Wed, 24 Jan 2018 09:30:15 +0000 (10:30 +0100)
src/bindings/java/jmsg_vm.cpp
src/bindings/java/jmsg_vm.h
src/bindings/java/org/simgrid/msg/VM.java

index 25256f7..06814bf 100644 (file)
@@ -134,8 +134,15 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_start(JNIEnv *env, jobject jvm)
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_shutdown(JNIEnv *env, jobject jvm)
 {
   msg_vm_t vm = jvm_get_native(env,jvm);
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_shutdown(JNIEnv *env, jobject jvm)
 {
   msg_vm_t vm = jvm_get_native(env,jvm);
-  if (vm) {
+  if (vm)
     MSG_vm_shutdown(vm);
     MSG_vm_shutdown(vm);
+}
+
+JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_destroy(JNIEnv* env, jobject jvm)
+{
+  msg_vm_t vm = jvm_get_native(env, jvm);
+  if (vm) {
+    MSG_vm_destroy(vm);
     auto vmList = &simgrid::vm::VirtualMachineImpl::allVms_;
     vmList->erase(std::remove(vmList->begin(), vmList->end(), vm), vmList->end());
   }
     auto vmList = &simgrid::vm::VirtualMachineImpl::allVms_;
     vmList->erase(std::remove(vmList->begin(), vmList->end(), vm), vmList->end());
   }
index d6fec6c..88c3619 100644 (file)
@@ -46,6 +46,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_nativeMigration(JNIEnv* env, jobj
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_suspend(JNIEnv* env, jobject jvm);
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_resume(JNIEnv* env, jobject jvm);
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_shutdown(JNIEnv* env, jobject jvm);
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_suspend(JNIEnv* env, jobject jvm);
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_resume(JNIEnv* env, jobject jvm);
 JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_shutdown(JNIEnv* env, jobject jvm);
+JNIEXPORT void JNICALL Java_org_simgrid_msg_VM_destroy(JNIEnv* env, jobject jvm);
 
 SG_END_DECL()
 
 
 SG_END_DECL()
 
index cdd7cd7..c26a85c 100644 (file)
@@ -66,18 +66,6 @@ public class VM extends Host {
 
        /** Retrieve a VM from its name */
        public static native VM getVMByName(String name);
 
        /** Retrieve a VM from its name */
        public static native VM getVMByName(String name);
-       
-       /** Shutdown and unref the VM. 
-        * 
-        * Actually, this strictly equivalent to shutdown().
-        * In C and in libvirt, the destroy function also releases the memory associated to the VM, 
-        * but this is not the way it goes in Java. The VM will only get destroyed by the garbage 
-        * collector when it is not referenced anymore by your variables. So, to see the VM really 
-        * destroyed, don't call this function but simply release any ref you have on it. 
-        */
-       public void destroy() {
-               shutdown();
-       }
 
        /* Make sure that the GC also destroys the C object */
        protected void finalize() throws Throwable {
 
        /* Make sure that the GC also destroys the C object */
        protected void finalize() throws Throwable {
@@ -110,7 +98,6 @@ public class VM extends Host {
         */
        private native void create(Host host, String name, int coreAmount, int ramSize, int migNetSpeed, int dpIntensity);
 
         */
        private native void create(Host host, String name, int coreAmount, int ramSize, int migNetSpeed, int dpIntensity);
 
-
        /**
         * Set a CPU bound for a given VM.
         * @param bound in flops/s
        /**
         * Set a CPU bound for a given VM.
         * @param bound in flops/s
@@ -120,7 +107,6 @@ public class VM extends Host {
        /**  start the VM */
        public native void start();
 
        /**  start the VM */
        public native void start();
 
-
        /**
         * Immediately kills all processes within the given VM. 
         * 
        /**
         * Immediately kills all processes within the given VM. 
         * 
@@ -128,6 +114,9 @@ public class VM extends Host {
         */
        public native void shutdown();
 
         */
        public native void shutdown();
 
+       /** Shutdown and unref the VM. */
+       public native void destroy();
+
        /** Change the host on which all processes are running
         * (pre-copy is implemented)
         */     
        /** Change the host on which all processes are running
         * (pre-copy is implemented)
         */     
@@ -145,17 +134,15 @@ public class VM extends Host {
 
        /** Immediately suspend the execution of all processes within the given VM
         *
 
        /** Immediately suspend the execution of all processes within the given VM
         *
-        * No suspension cost occurs. If you want to simulate this too, you want to
-        * use a \ref File.write() before or after, depending on the exact semantic
-        * of VM suspend to you.
+        * No suspension cost occurs. If you want to simulate this too, you want to use a \ref File.write() before or 
+        * after, depending on the exact semantic of VM suspend to you.
         */     
        public native void suspend();
 
        /** Immediately resumes the execution of all processes within the given VM
         *
         */     
        public native void suspend();
 
        /** Immediately resumes the execution of all processes within the given VM
         *
-        * No resume cost occurs. If you want to simulate this too, you want to
-        * use a \ref File.read() before or after, depending on the exact semantic
-        * of VM resume to you.
+        * No resume cost occurs. If you want to simulate this too, you want to use a \ref File.read() before or after, 
+        * depending on the exact semantic of VM resume to you.
         */
        public native void resume();
 
         */
        public native void resume();