From d77b1484a375297cabd5ef038ed056cc5ccee367 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Wed, 24 Jan 2018 10:30:15 +0100 Subject: [PATCH] distinguish shutdown and destroy in Java VMs --- src/bindings/java/jmsg_vm.cpp | 9 +++++++- src/bindings/java/jmsg_vm.h | 1 + src/bindings/java/org/simgrid/msg/VM.java | 27 ++++++----------------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/bindings/java/jmsg_vm.cpp b/src/bindings/java/jmsg_vm.cpp index 25256f7b49..06814bf3d9 100644 --- a/src/bindings/java/jmsg_vm.cpp +++ b/src/bindings/java/jmsg_vm.cpp @@ -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); - if (vm) { + if (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()); } diff --git a/src/bindings/java/jmsg_vm.h b/src/bindings/java/jmsg_vm.h index d6fec6c1e1..88c3619fad 100644 --- a/src/bindings/java/jmsg_vm.h +++ b/src/bindings/java/jmsg_vm.h @@ -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_destroy(JNIEnv* env, jobject jvm); SG_END_DECL() diff --git a/src/bindings/java/org/simgrid/msg/VM.java b/src/bindings/java/org/simgrid/msg/VM.java index cdd7cd797d..c26a85c058 100644 --- a/src/bindings/java/org/simgrid/msg/VM.java +++ b/src/bindings/java/org/simgrid/msg/VM.java @@ -66,18 +66,6 @@ public class VM extends Host { /** 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 { @@ -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); - /** * 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(); - /** * Immediately kills all processes within the given VM. * @@ -128,6 +114,9 @@ public class VM extends Host { */ 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) */ @@ -145,17 +134,15 @@ public class VM extends Host { /** 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 * - * 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(); -- 2.20.1