Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix memory leak when process killed. Fix bug where the simulation could crash when...
authorSamuel Lepetit <samuel.lepetit@inria.fr>
Tue, 19 Jun 2012 09:34:05 +0000 (11:34 +0200)
committerSamuel Lepetit <samuel.lepetit@inria.fr>
Tue, 19 Jun 2012 09:34:05 +0000 (11:34 +0200)
org/simgrid/msg/Comm.java
org/simgrid/msg/VM.java
src/jmsg_comm.c
src/jmsg_file.c
src/jmsg_host.c
src/jmsg_process.c
src/jmsg_synchro.c
src/jmsg_task.c
src/jmsg_vm.c
src/jmsg_vm.h

index b3cdfac..66d264c 100644 (file)
@@ -69,6 +69,7 @@ public class Comm {
         * @param timeout Time before giving up
         */
        public native void waitCompletion(double timeout) throws TransferFailureException, HostFailureException, TimeoutException;
+               
        /**
         * Returns the task associated with the communication.
         * if the communication isn't finished yet, will return null.
index c23fd34..cdbcdd4 100644 (file)
@@ -31,6 +31,13 @@ public class VM {
                this.coreAmount = coreAmount;
                start(host,coreAmount);
        }
+       protected void finalize() {
+               destroy();
+       }
+       /**
+        * Destroy the VM
+        */
+       protected native void destroy();
        /**
         * Natively implemented method starting the VM.
         * @param coreAmount
index 8c3d65c..87dc0ec 100644 (file)
@@ -82,6 +82,7 @@ Java_org_simgrid_msg_Comm_test(JNIEnv *env, jobject jcomm) {
     jxbt_throw_native(env,bprintf("comm is null"));
     return JNI_FALSE;
   }
+  xbt_ex_t e;
   TRY {
     if (MSG_comm_test(comm)) {
       MSG_error_t status = MSG_comm_get_status(comm);
@@ -99,9 +100,10 @@ Java_org_simgrid_msg_Comm_test(JNIEnv *env, jobject jcomm) {
       return JNI_FALSE;
     }
   }
-  CATCH_ANONYMOUS {
-
+  CATCH(e) {
+    xbt_ex_free(e);
   }
+
   return JNI_FALSE;
 }
 JNIEXPORT void JNICALL
@@ -118,11 +120,12 @@ Java_org_simgrid_msg_Comm_waitCompletion(JNIEnv *env, jobject jcomm, jdouble tim
   }
 
   MSG_error_t status;
+  xbt_ex_t e;
   TRY {
     status = MSG_comm_wait(comm,(double)timeout);
   }
-  CATCH_ANONYMOUS {
-    return;
+  CATCH(e) {
+    xbt_ex_free(e);
   }
   (*env)->SetBooleanField(env, jcomm, jcomm_field_Comm_finished, JNI_TRUE);
   if (status == MSG_OK) {
index 2b00cba..36650e2 100644 (file)
@@ -26,9 +26,14 @@ Java_org_simgrid_msg_File_open(JNIEnv *env, jobject jfile, jobject jstorage, job
   const char *storage = (*env)->GetStringUTFChars(env, jstorage, 0);
   const char *path = (*env)->GetStringUTFChars(env, jpath, 0);
   const char *mode = (*env)->GetStringUTFChars(env, jmode, 0);
-
-  msg_file_t file = MSG_file_open(storage, path, mode);
-
+  msg_file_t file;
+  xbt_ex_t e;
+  TRY {
+    file = MSG_file_open(storage, path, mode);
+  }
+  CATCH(e) {
+    xbt_ex_free(e);
+  }
   jfile_bind(env, jfile, file);
 
   (*env)->ReleaseStringUTFChars(env, jstorage, storage);
@@ -38,18 +43,28 @@ Java_org_simgrid_msg_File_open(JNIEnv *env, jobject jfile, jobject jstorage, job
 JNIEXPORT jlong JNICALL
 Java_org_simgrid_msg_File_read(JNIEnv *env, jobject jfile, jlong jsize, jlong jnmemb) {
   msg_file_t file = jfile_get_native(env, jfile);
-
-  size_t n = MSG_file_read(NULL,(size_t)jsize, (size_t)jnmemb, file);
-
+  size_t n;
+  xbt_ex_t e;
+  TRY {
+    n = MSG_file_read(NULL,(size_t)jsize, (size_t)jnmemb, file);
+  }
+  CATCH (e) {
+    xbt_ex_free(e);
+  }
   return (jlong)n;
 }
 
 JNIEXPORT jlong JNICALL
 Java_org_simgrid_msg_File_write(JNIEnv *env, jobject jfile, jlong jsize, jlong jnmemb) {
   msg_file_t file = jfile_get_native(env, jfile);
-
-  size_t n = MSG_file_write(NULL, (size_t)jsize, (size_t)jnmemb, file);
-
+  xbt_ex_t e;
+  size_t n;
+  TRY {
+     n = MSG_file_write(NULL, (size_t)jsize, (size_t)jnmemb, file);
+  }
+  CATCH(e) {
+    xbt_ex_free(e);
+  }
   return (jlong)n;
 }
 JNIEXPORT void JNICALL
index f48be36..5baed08 100644 (file)
@@ -74,10 +74,8 @@ Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jclass cls,
        jxbt_throw_null(env,bprintf("No host can have a null name"));
        return NULL;
   }
-  XBT_DEBUG("Looking for host '%s'",name);
   /* get the host by name       (the hosts are created during the grid resolution) */
   host = MSG_get_host_by_name(name);
-  XBT_DEBUG("MSG gave %p as native host", host);
 
   if (!host) {                  /* invalid name */
     jxbt_throw_host_not_found(env, name);
index 3ff056f..8150939 100644 (file)
@@ -265,10 +265,12 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_sleep
 
        double time =  jmillis / 1000 + jnanos / 1000;
        MSG_error_t rv;
+       xbt_ex_t e;
        TRY {
                rv = MSG_process_sleep(time);
        }
-       CATCH_ANONYMOUS {
+       CATCH(e) {
+           xbt_ex_free(e);
                return;
        }
   if (rv != MSG_OK) {
@@ -280,10 +282,12 @@ Java_org_simgrid_msg_Process_waitFor(JNIEnv * env, jobject jprocess,
                                      jdouble jseconds)
 {
   MSG_error_t rv;
+  xbt_ex_t e;
   TRY {
    rv = MSG_process_sleep((double)jseconds);
   }
-  CATCH_ANONYMOUS {
+  CATCH(e) {
+    xbt_ex_free(e);
        return;
   }
   if (rv != MSG_OK) {
@@ -325,8 +329,9 @@ Java_org_simgrid_msg_Process_migrate(JNIEnv * env,
 
   /* try to change the host of the process */
   MSG_error_t rv = MSG_process_migrate(process, host);
-  jxbt_check_res("MSG_process_migrate()", rv, MSG_OK,
-                 bprintf("unexpected error , please report this bug"));
+  if (rv != MSG_OK) {
+    jmsg_throw_status(env,rv);
+  }
   /* change the host java side */
   (*env)->SetObjectField(env, jprocess, jprocess_field_Process_host, jhost);
 }
index 8424a70..35acc6f 100644 (file)
@@ -31,7 +31,13 @@ Java_org_simgrid_msg_Mutex_acquire(JNIEnv * env, jobject obj) {
   xbt_mutex_t mutex;
 
   mutex = (xbt_mutex_t) (long) (*env)->GetLongField(env, obj, jsyncro_field_Mutex_bind);
-  xbt_mutex_acquire(mutex);
+  xbt_ex_t e;
+  TRY {
+    xbt_mutex_acquire(mutex);
+  }
+  CATCH(e) {
+    xbt_ex_free(e);
+  }
 }
 
 JNIEXPORT void JNICALL
index aaa9747..00a065d 100644 (file)
@@ -215,11 +215,13 @@ Java_org_simgrid_msg_Task_execute(JNIEnv * env,
     jxbt_throw_notbound(env, "task", jtask);
     return;
   }
+  xbt_ex_t e;
   MSG_error_t rv;
   TRY {
      rv = MSG_task_execute(task);
   }
-  CATCH_ANONYMOUS {
+  CATCH(e) {
+    xbt_ex_free(e);
        return;
   }
   if (rv != MSG_OK) {
@@ -364,8 +366,13 @@ Java_org_simgrid_msg_Task_send(JNIEnv * env,jobject jtask,
 
   /* Pass a global ref to the Jtask into the Ctask so that the receiver can use it */
   MSG_task_set_data(task, (void *) (*env)->NewGlobalRef(env, jtask));
-  rv = MSG_task_send_with_timeout(task, alias, (double) jtimeout);
-
+  xbt_ex_t e;
+  TRY {
+    rv = MSG_task_send_with_timeout(task, alias, (double) jtimeout);
+  }
+  CATCH(e) {
+    xbt_ex_free(e);
+  }
   (*env)->ReleaseStringUTFChars(env, jalias, alias);
 
   if (rv != MSG_OK) {
@@ -391,16 +398,19 @@ Java_org_simgrid_msg_Task_sendBounded(JNIEnv * env, jobject jtask,
 
   /* Pass a global ref to the Jtask into the Ctask so that the receiver can use it */
   MSG_task_set_data(task, (void *) (*env)->NewGlobalRef(env, jtask));
-  rv = MSG_task_send_bounded(task, alias, (double) jmaxRate);
 
+  xbt_ex_t e;
+  TRY {
+    rv = MSG_task_send_bounded(task, alias, (double) jmaxRate);
+  }
+  CATCH(e) {
+    xbt_ex_free(e);
+  }
   (*env)->ReleaseStringUTFChars(env, jalias, alias);
 
-  jxbt_check_res("MSG_task_send_bounded()", rv,
-                 MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT,
-                 bprintf
-                 ("while sending task %s to mailbox %s with max rate %f",
-                  MSG_task_get_name(task), alias, (double) jmaxRate));
-
+  if (rv != MSG_OK) {
+    jmsg_throw_status(env, rv);
+  }
 }
 
 
@@ -427,10 +437,12 @@ Java_org_simgrid_msg_Task_receive(JNIEnv * env, jclass cls,
   }
 
   alias = (*env)->GetStringUTFChars(env, jalias, 0);
+  xbt_ex_t e;
   TRY {
        rv = MSG_task_receive_ext(task, alias, (double) jtimeout, host);
   }
-  CATCH_ANONYMOUS {
+  CATCH(e) {
+    xbt_ex_free(e);
        return NULL;
   }
   if (rv != MSG_OK) {
@@ -448,10 +460,6 @@ Java_org_simgrid_msg_Task_receive(JNIEnv * env, jclass cls,
 
   xbt_free(task);
 
-  jxbt_check_res("MSG_task_receive_ext()", rv,
-                 MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT,
-                 bprintf("while receiving from mailbox %s", alias));
-
   return (jobject) jtask_local;
 }
 
@@ -568,12 +576,14 @@ Java_org_simgrid_msg_Task_listen(JNIEnv * env, jclass cls,
 
   const char *alias;
   int rv;
+  xbt_ex_t e;
 
   alias = (*env)->GetStringUTFChars(env, jalias, 0);
   TRY {
        rv = MSG_task_listen(alias);
   }
-  CATCH_ANONYMOUS {
+  CATCH(e) {
+    xbt_ex_free(e);
        return 0;
   }
   (*env)->ReleaseStringUTFChars(env, jalias, alias);
@@ -595,10 +605,13 @@ Java_org_simgrid_msg_Task_listenFromHost(JNIEnv * env, jclass cls,
     return -1;
   }
   alias = (*env)->GetStringUTFChars(env, jalias, 0);
+  xbt_ex_t e;
+
   TRY {
        rv = MSG_task_listen_from_host(alias, host);
   }
-  CATCH_ANONYMOUS {
+  CATCH(e) {
+    xbt_ex_free(e);
        return 0;
   }
   (*env)->ReleaseStringUTFChars(env, jalias, alias);
@@ -613,10 +626,12 @@ Java_org_simgrid_msg_Task_listenFrom(JNIEnv * env, jclass cls,
 
   int rv;
   const char *alias = (*env)->GetStringUTFChars(env, jalias, 0);
+  xbt_ex_t e;
   TRY {
        rv = MSG_task_listen_from(alias);
   }
-  CATCH_ANONYMOUS {
+  CATCH(e) {
+    xbt_ex_free(e);
        return 0;
   }
   (*env)->ReleaseStringUTFChars(env, jalias, alias);
index bd04d43..3e0eb2c 100644 (file)
@@ -8,7 +8,7 @@
 #include "jmsg_host.h"
 #include "jmsg_process.h"
 #include "jxbt_utilities.h"
-
+#include "msg/msg.h"
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
 
 void jvm_bind(JNIEnv *env, jobject jvm, msg_vm_t vm) {
@@ -35,7 +35,11 @@ Java_org_simgrid_msg_VM_start(JNIEnv *env, jobject jvm, jobject jhost, jint jcor
 
   jvm_bind(env,jvm,vm);
 }
-
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_VM_destroy(JNIEnv *env, jobject jvm) {
+  /*msg_vm_t vm = jvm_get_native(env,jvm);
+  MSG_vm_destroy(vm);*/
+}
 JNIEXPORT jboolean JNICALL
 Java_org_simgrid_msg_VM_isSuspended(JNIEnv *env, jobject jvm) {
   msg_vm_t vm = jvm_get_native(env,jvm);
@@ -75,18 +79,33 @@ Java_org_simgrid_msg_VM_migrate(JNIEnv *env, jobject jvm, jobject jhost) {
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_VM_suspend(JNIEnv *env, jobject jvm) {
   msg_vm_t vm = jvm_get_native(env,jvm);
-
-  MSG_vm_suspend(vm);
+  xbt_ex_t e;
+  TRY {
+    MSG_vm_suspend(vm);
+  }
+  CATCH(e) {
+    xbt_ex_free(e);
+  }
 }
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_VM_resume(JNIEnv *env, jobject jvm) {
   msg_vm_t vm = jvm_get_native(env,jvm);
-
-  MSG_vm_resume(vm);
+  xbt_ex_t e;
+  TRY {
+    MSG_vm_resume(vm);
+  }
+  CATCH(e) {
+    xbt_ex_free(e);
+  }
 }
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_VM_shutdown(JNIEnv *env, jobject jvm) {
   msg_vm_t vm = jvm_get_native(env,jvm);
-
-  MSG_vm_shutdown(vm);
+  xbt_ex_t e;
+  TRY {
+    MSG_vm_shutdown(vm);
+  }
+  CATCH(e) {
+    xbt_ex_free(e);
+  }
 }
index 0acedc5..6266bf6 100644 (file)
@@ -32,12 +32,12 @@ Java_org_simgrid_msg_VM_nativeInit(JNIEnv *env, jclass);
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_VM_start(JNIEnv *env, jobject jvm, jobject jhost, jint jcoreamount);
 /**
- * Class                       org_simgrid_msg_VM
- * Method                      all
- * Signature   ()[Lorg/simgrid/msg/VM;
+ * Class            org_simgrid_msg_VM
+ * Method           destroy
+ * Signature    ()V
  */
-JNIEXPORT jobjectArray JNICALL
-Java_org_simgrid_msg_VM_all(JNIEnv *env, jclass cls);
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_VM_destroy(JNIEnv *env, jobject jvm);
 /**
  * Class                       org_simgrid_msg_VM
  * Method                      isSuspended