From: Gabriel Corona Date: Mon, 27 Apr 2015 08:33:01 +0000 (+0200) Subject: Merge branch 'master' into mc X-Git-Tag: v3_12~732^2~50 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/d13b1659a0c2551ee41b287a269e391bb2d7bc8a?hp=510d3716010b117855620a4e79f0ba78de43346d Merge branch 'master' into mc Conflicts: buildtools/Cmake/DefinePackages.cmake src/mc/mc_request.cpp --- diff --git a/ChangeLog b/ChangeLog index dc3e85d4e0..455983dd86 100644 --- a/ChangeLog +++ b/ChangeLog @@ -16,6 +16,8 @@ SimGrid (3.12) NOT RELEASED; urgency=low - Rename Process.currentProcess() to Process.getCurrentProcess() - Rename Task.setDataSize() to Task.setBytesAmount() - Merge Task.getRemainingDuration() and Task.getComputeDuration() into Task.getFlopsAmount() + * Bug fixes: + - #18874: Actually allows the GC to reclaim tasks SIMIX: * New functions @@ -30,6 +32,8 @@ SimGrid (3.12) NOT RELEASED; urgency=low For example, a communication is a sort of synchronization involving the communicating processes (that may block until the exchange) and the platform. The same can be said from computations, etc. + * Bug fixes: + - #18888: segfault when a process ends before its kill_time SMPI: * New functions diff --git a/buildtools/Cmake/DefinePackages.cmake b/buildtools/Cmake/DefinePackages.cmake index b08922fe1f..d62ea0c557 100644 --- a/buildtools/Cmake/DefinePackages.cmake +++ b/buildtools/Cmake/DefinePackages.cmake @@ -619,6 +619,7 @@ set(MC_SRC src/mc/mc_dwarf_tagnames.h src/mc/mc_hash.cpp src/mc/mc_ignore.cpp + src/mc/mc_ignore.h src/mc/mc_liveness.h src/mc/mc_location.h src/mc/mc_liveness.cpp diff --git a/examples/java/cloud/Master.java b/examples/java/cloud/Master.java index a581aff8cc..d3606c90dc 100644 --- a/examples/java/cloud/Master.java +++ b/examples/java/cloud/Master.java @@ -81,7 +81,6 @@ public class Master extends Process { for (int i = 0; i < vms.size(); i++) { vms.get(i).shutdown(); - vms.get(i).destroy(); } Msg.info("Master done."); } diff --git a/examples/java/cloud/migration/Test.java b/examples/java/cloud/migration/Test.java index 7edd53808f..b697049f8e 100644 --- a/examples/java/cloud/migration/Test.java +++ b/examples/java/cloud/migration/Test.java @@ -144,8 +144,9 @@ public class Test extends Process{ Msg.info(" - End of Migration from host 1 to host 0 (duration:"+(endTime-startTime)+")"); Main.setEndOfTest(); - Msg.info("Destroy VMs"); + Msg.info("Forcefully destroy VMs"); for (VM vm: vms) - vm.destroy(); + vm.finalize(); + } } diff --git a/examples/java/cloud/migration/TestHostOnOff.java b/examples/java/cloud/migration/TestHostOnOff.java index 1f4278fcb7..47467bd178 100644 --- a/examples/java/cloud/migration/TestHostOnOff.java +++ b/examples/java/cloud/migration/TestHostOnOff.java @@ -121,16 +121,15 @@ public class TestHostOnOff extends Process{ Process.sleep(50000); Msg.info("Destroy VMs"); vm0.shutdown(); - vm0.destroy(); Process.sleep(20000); } public static void test_vm_shutdown_destroy () throws HostFailureException { - Msg.info("**** **** **** ***** ***** Test shutdown /destroy a VM ***** ***** **** **** ****"); + Msg.info("**** **** **** ***** ***** Test shutdown a VM ***** ***** **** **** ****"); Msg.info("Turn on host1, assign a VM on host1, launch a process inside the VM, and turn off the vm, " + - "destroy it and check whether you can reallocate the same VM"); + "and check whether you can reallocate the same VM"); // Create VM0 @@ -156,10 +155,7 @@ public class TestHostOnOff extends Process{ Msg.info("Shutdown VM0"); vm0.shutdown(); Process.sleep(5000); - Msg.info("Destroy VM0"); - vm0.destroy(); - Process.sleep(5000); Msg.info("Restart VM0"); vm0 = new XVM( host1, @@ -179,8 +175,6 @@ public class TestHostOnOff extends Process{ Process.sleep(5000); vm0.shutdown(); - Process.sleep(5000); - vm0.destroy(); } } diff --git a/examples/msg/start_kill_time/deployment.xml b/examples/msg/start_kill_time/deployment.xml index fefeb8e1dc..c9b5c37ec1 100644 --- a/examples/msg/start_kill_time/deployment.xml +++ b/examples/msg/start_kill_time/deployment.xml @@ -1,10 +1,8 @@ - - - - - - + + + + diff --git a/examples/msg/start_kill_time/deployment_kill.xml b/examples/msg/start_kill_time/deployment_kill.xml index 39cdf4e27b..056979d3ec 100644 --- a/examples/msg/start_kill_time/deployment_kill.xml +++ b/examples/msg/start_kill_time/deployment_kill.xml @@ -1,10 +1,7 @@ - - - - - - + + + diff --git a/examples/msg/start_kill_time/deployment_start.xml b/examples/msg/start_kill_time/deployment_start.xml index 203df2bc22..39af2ab593 100644 --- a/examples/msg/start_kill_time/deployment_start.xml +++ b/examples/msg/start_kill_time/deployment_start.xml @@ -1,10 +1,10 @@ - - - - - - + + + + + + diff --git a/examples/msg/start_kill_time/deployment_start_kill.xml b/examples/msg/start_kill_time/deployment_start_kill.xml index d4beac46e7..0a6d5cad3c 100644 --- a/examples/msg/start_kill_time/deployment_start_kill.xml +++ b/examples/msg/start_kill_time/deployment_start_kill.xml @@ -1,10 +1,10 @@ - - - - - - + + + + + + diff --git a/examples/msg/start_kill_time/sk_time.c b/examples/msg/start_kill_time/sk_time.c index af50303903..3ade8f030e 100644 --- a/examples/msg/start_kill_time/sk_time.c +++ b/examples/msg/start_kill_time/sk_time.c @@ -1,10 +1,10 @@ -/* Copyright (c) 2007, 2009-2010, 2012-2014. The SimGrid Team. +/* Copyright (c) 2007, 2009-2010, 2012-2015. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -#include "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */ +#include "simgrid/msg.h" /* Yeah! If you want to use msg, you need to include simgrid/msg.h */ #include "xbt/sysdep.h" /* calloc */ /* Create a log channel to have nice outputs. */ @@ -12,22 +12,20 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); -/** Lazy guy function. This process suspends itself asap. */ -static int slave(int argc, char *argv[]) -{ - XBT_INFO("Hello!"); - MSG_process_sleep(10.0); - XBT_INFO("OK, goodbye now."); +static int my_onexit(void* ignored1, void *ignored2) { + XBT_INFO("Exiting now (done sleeping or got killed)."); return 0; -} /* end_of_lazy_guy */ +} -static int master(int argc, char *argv[]) +static int sleeper(int argc, char *argv[]) { - XBT_INFO("Hello!"); - MSG_process_sleep(10.0); - XBT_INFO("OK, goodbye now."); + XBT_INFO("Hello! I go to sleep."); + MSG_process_on_exit(my_onexit, NULL); + + MSG_process_sleep(atoi(argv[1])); + XBT_INFO("Done sleeping."); return 0; -} /* end_of_dram_master */ +} /** Test function */ static msg_error_t test_all(const char *platform_file, @@ -36,8 +34,7 @@ static msg_error_t test_all(const char *platform_file, msg_error_t res = MSG_OK; MSG_create_environment(platform_file); - MSG_function_register("master", master); - MSG_function_register("slave", slave); + MSG_function_register("sleeper", sleeper); MSG_launch_application(application_file); res = MSG_main(); diff --git a/examples/msg/start_kill_time/start_kill_time.tesh b/examples/msg/start_kill_time/start_kill_time.tesh index 4e98d61fad..b0cd29c9c0 100644 --- a/examples/msg/start_kill_time/start_kill_time.tesh +++ b/examples/msg/start_kill_time/start_kill_time.tesh @@ -3,57 +3,61 @@ p Test0 Process without time $ $SG_TEST_EXENV ${bindir:=.}/start_kill_time/sk_time ${srcdir:=.}/examples/platforms/cluster.xml ${srcdir:=.}/examples/msg/start_kill_time/deployment.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" -> [ 0.000000] (1:master@node-0.acme.org) Hello! -> [ 0.000000] (2:slave@node-1.acme.org) Hello! -> [ 0.000000] (3:slave@node-2.acme.org) Hello! -> [ 0.000000] (4:slave@node-3.acme.org) Hello! -> [ 0.000000] (5:slave@node-4.acme.org) Hello! -> [ 0.000000] (6:slave@node-5.acme.org) Hello! -> [ 10.000000] (6:slave@node-5.acme.org) OK, goodbye now. -> [ 10.000000] (1:master@node-0.acme.org) OK, goodbye now. -> [ 10.000000] (2:slave@node-1.acme.org) OK, goodbye now. -> [ 10.000000] (3:slave@node-2.acme.org) OK, goodbye now. -> [ 10.000000] (4:slave@node-3.acme.org) OK, goodbye now. -> [ 10.000000] (5:slave@node-4.acme.org) OK, goodbye now. +> [ 0.000000] (1:sleeper@node-0.acme.org) Hello! I go to sleep. +> [ 10.000000] (1:sleeper@node-0.acme.org) Done sleeping. +> [ 10.000000] (1:sleeper@node-0.acme.org) Exiting now (done sleeping or got killed). > [ 10.000000] (0:@) Simulation time 10 p Test1 Process with start time $ $SG_TEST_EXENV ${bindir:=.}/start_kill_time/sk_time ${srcdir:=.}/examples/platforms/cluster.xml ${srcdir:=.}/examples/msg/start_kill_time/deployment_start.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" -> [ 0.000000] (1:master@node-0.acme.org) Hello! -> [ 1.000000] (2:slave@node-1.acme.org) Hello! -> [ 2.000000] (3:slave@node-2.acme.org) Hello! -> [ 3.000000] (4:slave@node-3.acme.org) Hello! -> [ 4.000000] (5:slave@node-4.acme.org) Hello! -> [ 5.000000] (6:slave@node-5.acme.org) Hello! -> [ 10.000000] (1:master@node-0.acme.org) OK, goodbye now. -> [ 11.000000] (2:slave@node-1.acme.org) OK, goodbye now. -> [ 12.000000] (3:slave@node-2.acme.org) OK, goodbye now. -> [ 13.000000] (4:slave@node-3.acme.org) OK, goodbye now. -> [ 14.000000] (5:slave@node-4.acme.org) OK, goodbye now. -> [ 15.000000] (6:slave@node-5.acme.org) OK, goodbye now. +> [ 0.000000] (1:sleeper@node-0.acme.org) Hello! I go to sleep. +> [ 1.000000] (2:sleeper@node-1.acme.org) Hello! I go to sleep. +> [ 2.000000] (3:sleeper@node-2.acme.org) Hello! I go to sleep. +> [ 3.000000] (4:sleeper@node-3.acme.org) Hello! I go to sleep. +> [ 4.000000] (5:sleeper@node-4.acme.org) Hello! I go to sleep. +> [ 5.000000] (6:sleeper@node-5.acme.org) Hello! I go to sleep. +> [ 10.000000] (1:sleeper@node-0.acme.org) Done sleeping. +> [ 10.000000] (1:sleeper@node-0.acme.org) Exiting now (done sleeping or got killed). +> [ 11.000000] (2:sleeper@node-1.acme.org) Done sleeping. +> [ 11.000000] (2:sleeper@node-1.acme.org) Exiting now (done sleeping or got killed). +> [ 12.000000] (3:sleeper@node-2.acme.org) Done sleeping. +> [ 12.000000] (3:sleeper@node-2.acme.org) Exiting now (done sleeping or got killed). +> [ 13.000000] (4:sleeper@node-3.acme.org) Done sleeping. +> [ 13.000000] (4:sleeper@node-3.acme.org) Exiting now (done sleeping or got killed). +> [ 14.000000] (5:sleeper@node-4.acme.org) Done sleeping. +> [ 14.000000] (5:sleeper@node-4.acme.org) Exiting now (done sleeping or got killed). +> [ 15.000000] (6:sleeper@node-5.acme.org) Done sleeping. +> [ 15.000000] (6:sleeper@node-5.acme.org) Exiting now (done sleeping or got killed). > [ 15.000000] (0:@) Simulation time 15 p Test1 Process with kill time $ $SG_TEST_EXENV ${bindir:=.}/start_kill_time/sk_time ${srcdir:=.}/examples/platforms/cluster.xml ${srcdir:=.}/examples/msg/start_kill_time/deployment_kill.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" -> [ 0.000000] (1:master@node-0.acme.org) Hello! -> [ 0.000000] (2:slave@node-1.acme.org) Hello! -> [ 0.000000] (3:slave@node-2.acme.org) Hello! -> [ 0.000000] (4:slave@node-3.acme.org) Hello! -> [ 0.000000] (5:slave@node-4.acme.org) Hello! -> [ 0.000000] (6:slave@node-5.acme.org) Hello! -> [ 10.000000] (1:master@node-0.acme.org) OK, goodbye now. -> [ 10.000000] (0:@) Simulation time 10 +> [ 0.000000] (1:sleeper@node-1.acme.org) Hello! I go to sleep. +> [ 0.000000] (2:sleeper@node-2.acme.org) Hello! I go to sleep. +> [ 0.000000] (3:sleeper@node-3.acme.org) Hello! I go to sleep. +> [ 6.000000] (1:sleeper@node-1.acme.org) Exiting now (done sleeping or got killed). +> [ 6.000000] (2:sleeper@node-2.acme.org) Exiting now (done sleeping or got killed). +> [ 6.000000] (3:sleeper@node-3.acme.org) Done sleeping. +> [ 6.000000] (3:sleeper@node-3.acme.org) Exiting now (done sleeping or got killed). +> [ 6.000000] (0:@) Simulation time 6 p Test2 Process with start and kill times $ $SG_TEST_EXENV ${bindir:=.}/start_kill_time/sk_time ${srcdir:=.}/examples/platforms/cluster.xml ${srcdir:=.}/examples/msg/start_kill_time/deployment_start_kill.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" -> [ 0.000000] (1:master@node-0.acme.org) Hello! -> [ 1.000000] (2:slave@node-1.acme.org) Hello! -> [ 2.000000] (3:slave@node-2.acme.org) Hello! -> [ 3.000000] (4:slave@node-3.acme.org) Hello! -> [ 4.000000] (5:slave@node-4.acme.org) Hello! -> [ 5.000000] (6:slave@node-5.acme.org) Hello! -> [ 10.000000] (1:master@node-0.acme.org) OK, goodbye now. +> [ 0.000000] (1:sleeper@node-0.acme.org) Hello! I go to sleep. +> [ 1.000000] (2:sleeper@node-1.acme.org) Hello! I go to sleep. +> [ 2.000000] (3:sleeper@node-2.acme.org) Hello! I go to sleep. +> [ 3.000000] (4:sleeper@node-3.acme.org) Hello! I go to sleep. +> [ 4.000000] (5:sleeper@node-4.acme.org) Hello! I go to sleep. +> [ 5.000000] (1:sleeper@node-0.acme.org) Exiting now (done sleeping or got killed). +> [ 5.000000] (6:sleeper@node-5.acme.org) Hello! I go to sleep. +> [ 6.000000] (2:sleeper@node-1.acme.org) Exiting now (done sleeping or got killed). +> [ 6.000000] (3:sleeper@node-2.acme.org) Done sleeping. +> [ 6.000000] (3:sleeper@node-2.acme.org) Exiting now (done sleeping or got killed). +> [ 7.000000] (4:sleeper@node-3.acme.org) Done sleeping. +> [ 7.000000] (4:sleeper@node-3.acme.org) Exiting now (done sleeping or got killed). +> [ 9.000000] (5:sleeper@node-4.acme.org) Exiting now (done sleeping or got killed). +> [ 10.000000] (6:sleeper@node-5.acme.org) Exiting now (done sleeping or got killed). > [ 10.000000] (0:@) Simulation time 10 diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index a79adf3726..ba20c93bfc 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -52,8 +52,6 @@ typedef enum { } e_smx_state_t; /** @} */ -typedef struct s_smx_timer* smx_timer_t; - /* ******************************** Synchro ************************************ */ /** * \ingroup simix_synchro_management @@ -235,8 +233,12 @@ XBT_PUBLIC(void) SIMIX_run(void); XBT_PUBLIC(double) SIMIX_get_clock(void); /* Timer functions FIXME: should these be public? */ -XBT_PUBLIC(void) SIMIX_timer_set(double date, void *function, void *arg); +typedef struct s_smx_timer* smx_timer_t; + +XBT_PUBLIC(smx_timer_t) SIMIX_timer_set(double date, void *function, void *arg); +XBT_PUBLIC(void) SIMIX_timer_remove(smx_timer_t timer); XBT_PUBLIC(double) SIMIX_timer_next(void); +XBT_PUBLIC(double) SIMIX_timer_get_date(smx_timer_t timer); XBT_PUBLIC(void) SIMIX_display_process_status(void); diff --git a/include/xbt/heap.h b/include/xbt/heap.h index e0ddfb8dd3..dda24d486c 100644 --- a/include/xbt/heap.h +++ b/include/xbt/heap.h @@ -27,6 +27,7 @@ XBT_PUBLIC(int) xbt_heap_size(xbt_heap_t H); XBT_PUBLIC(void) xbt_heap_push(xbt_heap_t H, void *content, double key); XBT_PUBLIC(void *) xbt_heap_pop(xbt_heap_t H); +XBT_PUBLIC(void) xbt_heap_rm_elm(xbt_heap_t H, void *content, double key); XBT_PUBLIC(double) xbt_heap_maxkey(xbt_heap_t H); XBT_PUBLIC(void *) xbt_heap_maxcontent(xbt_heap_t H); diff --git a/src/bindings/java/jmsg_comm.c b/src/bindings/java/jmsg_comm.c index bf6a09b6fe..2de313cc50 100644 --- a/src/bindings/java/jmsg_comm.c +++ b/src/bindings/java/jmsg_comm.c @@ -62,7 +62,7 @@ Java_org_simgrid_msg_Comm_nativeInit(JNIEnv *env, jclass cls) { } JNIEXPORT void JNICALL -Java_org_simgrid_msg_Comm_destroy(JNIEnv *env, jobject jcomm) { +Java_org_simgrid_msg_Comm_nativeFinalize(JNIEnv *env, jobject jcomm) { msg_comm_t comm; msg_task_t *task_received; diff --git a/src/bindings/java/jmsg_comm.h b/src/bindings/java/jmsg_comm.h index ec099e9311..7849c6cc1c 100644 --- a/src/bindings/java/jmsg_comm.h +++ b/src/bindings/java/jmsg_comm.h @@ -20,7 +20,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_nativeInit(JNIEnv *env, jclass cls); JNIEXPORT void JNICALL -Java_org_simgrid_msg_Comm_destroy(JNIEnv *env, jobject jcomm); +Java_org_simgrid_msg_Comm_nativeFinalize(JNIEnv *env, jobject jcomm); JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Comm_test(JNIEnv *env, jobject jcomm); diff --git a/src/bindings/java/jmsg_rngstream.c b/src/bindings/java/jmsg_rngstream.c index 5bf195b31a..14afaae984 100644 --- a/src/bindings/java/jmsg_rngstream.c +++ b/src/bindings/java/jmsg_rngstream.c @@ -38,7 +38,7 @@ Java_org_simgrid_msg_RngStream_create(JNIEnv *env, jobject jrngstream, jstring j (*env)->ReleaseStringUTFChars(env, jname, name); } JNIEXPORT void JNICALL -Java_org_simgrid_msg_RngStream_destroy(JNIEnv *env, jobject jrngstream) { +Java_org_simgrid_msg_RngStream_nativeFinalize(JNIEnv *env, jobject jrngstream) { RngStream rngstream = jrngstream_to_native(env, jrngstream); RngStream_DeleteStream(&rngstream); (*env)->SetLongField(env, jrngstream, jrngstream_bind, (intptr_t)NULL); diff --git a/src/bindings/java/jmsg_rngstream.h b/src/bindings/java/jmsg_rngstream.h index e50b218de9..69457d3689 100644 --- a/src/bindings/java/jmsg_rngstream.h +++ b/src/bindings/java/jmsg_rngstream.h @@ -20,7 +20,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_RngStream_create(JNIEnv *env, jobject jrngstream, jstring name); JNIEXPORT void JNICALL -Java_org_simgrid_msg_RngStream_destroy(JNIEnv *env, jobject jrngstream); +Java_org_simgrid_msg_RngStream_nativeFinalize(JNIEnv *env, jobject jrngstream); JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_RngStream_setPackageSeed(JNIEnv *env, jobject jrngstream, jintArray seed); diff --git a/src/bindings/java/jmsg_synchro.c b/src/bindings/java/jmsg_synchro.c index 71ba2ef516..feaeac1ea9 100644 --- a/src/bindings/java/jmsg_synchro.c +++ b/src/bindings/java/jmsg_synchro.c @@ -52,7 +52,7 @@ Java_org_simgrid_msg_Mutex_release(JNIEnv * env, jobject obj) { } JNIEXPORT void JNICALL -Java_org_simgrid_msg_Mutex_exit(JNIEnv * env, jobject obj) { +Java_org_simgrid_msg_Mutex_nativeFinalize(JNIEnv * env, jobject obj) { xbt_mutex_t mutex; mutex = (xbt_mutex_t) (long) (*env)->GetLongField(env, obj, jsyncro_field_Mutex_bind); @@ -104,7 +104,7 @@ Java_org_simgrid_msg_Semaphore_wouldBlock(JNIEnv * env, jobject obj) { } JNIEXPORT void JNICALL -Java_org_simgrid_msg_Mutex_destroy(JNIEnv * env, jobject obj) { +Java_org_simgrid_msg_Semaphore_nativeFinalize(JNIEnv * env, jobject obj) { msg_sem_t sem; sem = (msg_sem_t) (long) (*env)->GetLongField(env, obj, jsyncro_field_Semaphore_bind); diff --git a/src/bindings/java/jmsg_synchro.h b/src/bindings/java/jmsg_synchro.h index d89ebcf318..87fd365bd6 100644 --- a/src/bindings/java/jmsg_synchro.h +++ b/src/bindings/java/jmsg_synchro.h @@ -26,7 +26,8 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Mutex_release(JNIEnv * env, jobject obj); JNIEXPORT void JNICALL -Java_org_simgrid_msg_Mutex_exit(JNIEnv * env, jobject obj); +Java_org_simgrid_msg_Mutex_nativeFinalize(JNIEnv * env, jobject obj); + JNIEXPORT void JNICALL Java_org_simgrid_msg_Semaphore_nativeInit(JNIEnv *env, jclass cls); @@ -39,5 +40,5 @@ Java_org_simgrid_msg_Semaphore_release(JNIEnv * env, jobject obj); JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Semaphore_wouldBlock(JNIEnv * env, jobject obj); JNIEXPORT void JNICALL -Java_org_simgrid_msg_Mutex_destroy(JNIEnv * env, jobject obj); +Java_org_simgrid_msg_Semaphore_nativeFinalize(JNIEnv * env, jobject obj); #endif /* !MSG_JPROCESS_H */ diff --git a/src/bindings/java/jmsg_task.c b/src/bindings/java/jmsg_task.c index 850a999a2c..3530569441 100644 --- a/src/bindings/java/jmsg_task.c +++ b/src/bindings/java/jmsg_task.c @@ -651,7 +651,17 @@ MSG_task_set_data(task, (void *) (*env)->NewGlobalRef(env, jtask)); return jcomm; } +JNIEXPORT void JNICALL +Java_org_simgrid_msg_Task_nativeFinalize(JNIEnv * env, jobject jtask) { + msg_task_t task = jtask_to_native_task(jtask, env); + + if (!task) { + jxbt_throw_notbound(env, "task", jtask); + return; + } + MSG_task_destroy(task); +} static void msg_task_cancel_on_failed_dsend(void*t) { msg_task_t task = t; diff --git a/src/bindings/java/jmsg_task.h b/src/bindings/java/jmsg_task.h index 77daa9fbd0..b79450a829 100644 --- a/src/bindings/java/jmsg_task.h +++ b/src/bindings/java/jmsg_task.h @@ -71,6 +71,8 @@ Java_org_simgrid_msg_Task_nativeInit(JNIEnv *env, jclass cls); JNIEXPORT void JNICALL Java_org_simgrid_msg_Task_create (JNIEnv * env, jobject jtask, jstring jname, jdouble jcomputeDuration, jdouble jmessageSize); +JNIEXPORT void JNICALL +Java_org_simgrid_msg_Task_nativeFinalize(JNIEnv * env, jobject jtask); /* * Class org_simgrid_msg_Task * Method parallelCreate diff --git a/src/bindings/java/jmsg_vm.c b/src/bindings/java/jmsg_vm.c index d16c3b0fcc..9338bdc1a3 100644 --- a/src/bindings/java/jmsg_vm.c +++ b/src/bindings/java/jmsg_vm.c @@ -104,7 +104,7 @@ Java_org_simgrid_msg_VM_create(JNIEnv *env, jobject jvm, jobject jhost, jstring } JNIEXPORT void JNICALL -Java_org_simgrid_msg_VM_destroy(JNIEnv *env, jobject jvm) { +Java_org_simgrid_msg_VM_nativeFinalize(JNIEnv *env, jobject jvm) { msg_vm_t vm = jvm_get_native(env,jvm); MSG_vm_destroy(vm); } diff --git a/src/bindings/java/jmsg_vm.h b/src/bindings/java/jmsg_vm.h index 5b97777087..5aca83358c 100644 --- a/src/bindings/java/jmsg_vm.h +++ b/src/bindings/java/jmsg_vm.h @@ -102,7 +102,7 @@ Java_org_simgrid_msg_VM_create(JNIEnv *env, jobject jvm, jobject jhost, jstring * Signature ()V */ JNIEXPORT void JNICALL -Java_org_simgrid_msg_VM_destroy(JNIEnv *env, jobject jvm); +Java_org_simgrid_msg_VM_nativeFinalize(JNIEnv *env, jobject jvm); /** * Class org_simgrid_msg_VM * Method start diff --git a/src/bindings/java/org/simgrid/msg/Comm.java b/src/bindings/java/org/simgrid/msg/Comm.java index ebe63fc16a..b4d2341024 100644 --- a/src/bindings/java/org/simgrid/msg/Comm.java +++ b/src/bindings/java/org/simgrid/msg/Comm.java @@ -40,32 +40,30 @@ public class Comm { protected Comm() { } - /** - * Finalize the communication object, destroying it. - */ - protected void finalize() throws Throwable { - destroy(); + /** Destroy the C communication object, when the GC reclaims the java part. */ + @Override + protected void finalize() { + try { + nativeFinalize(); + } catch (Throwable e) { + e.printStackTrace(); + } } - /** - * Unbind the communication object - */ - protected native void destroy() throws NativeException; + protected native void nativeFinalize(); /** * Returns if the communication is finished or not. * If the communication has finished and there was an error, * raise an exception. */ public native boolean test() throws TransferFailureException, HostFailureException, TimeoutException ; - /** - * Wait for the complemetion of the communication for an indefinite time - */ + /** Wait infinitely for the completion of the communication (infinite timeout) */ public void waitCompletion() throws TransferFailureException, HostFailureException, TimeoutException { waitCompletion(-1); } /** * Wait for the completion of the communication. * Throws an exception if there were an error in the communication. - * @param timeout Time before giving up + * @param timeout Time before giving up (infinite time if negative) */ public native void waitCompletion(double timeout) throws TransferFailureException, HostFailureException, TimeoutException; diff --git a/src/bindings/java/org/simgrid/msg/Mutex.java b/src/bindings/java/org/simgrid/msg/Mutex.java index fbcb6340a2..503588b3dd 100644 --- a/src/bindings/java/org/simgrid/msg/Mutex.java +++ b/src/bindings/java/org/simgrid/msg/Mutex.java @@ -16,10 +16,15 @@ public class Mutex { public Mutex() { init(); } + @Override protected void finalize() { - exit(); + try { + nativeFinalize(); + } catch (Throwable e) { + e.printStackTrace(); + } } - private native void exit(); + private native void nativeFinalize(); private native void init(); public native void acquire(); public native void release(); diff --git a/src/bindings/java/org/simgrid/msg/RngStream.java b/src/bindings/java/org/simgrid/msg/RngStream.java index c7d3a5d837..49e7ac3b9f 100644 --- a/src/bindings/java/org/simgrid/msg/RngStream.java +++ b/src/bindings/java/org/simgrid/msg/RngStream.java @@ -41,16 +41,18 @@ public class RngStream { * The natively implemented method to create a C RngStream object. */ private native void create(String name); - /** - * Destructor - */ + @Override protected void finalize() { - destroy(); + try { + nativeFinalize(); + } catch (Throwable e) { + e.printStackTrace(); + } } /** * Release the C RngStream object */ - private native void destroy(); + private native void nativeFinalize(); /** * Sets the initial seed of the package RngStreams to the six integers in the vector seed. This will diff --git a/src/bindings/java/org/simgrid/msg/Semaphore.java b/src/bindings/java/org/simgrid/msg/Semaphore.java index d74a8bcc9d..9be79f6a02 100644 --- a/src/bindings/java/org/simgrid/msg/Semaphore.java +++ b/src/bindings/java/org/simgrid/msg/Semaphore.java @@ -65,14 +65,16 @@ public class Semaphore { } - /** Deletes this semaphore - */ + /** Deletes this semaphore when the GC reclaims it */ + @Override protected void finalize() { - destroy(); + try { + nativeFinalize(); + } catch (Throwable e) { + e.printStackTrace(); + } } - /** The native implementation for destroying a semaphore - */ - private native void destroy(); + private native void nativeFinalize(); /** * Class initializer, to initialize various JNI stuff */ diff --git a/src/bindings/java/org/simgrid/msg/Task.java b/src/bindings/java/org/simgrid/msg/Task.java index 95893ec91a..0ee65c4b81 100644 --- a/src/bindings/java/org/simgrid/msg/Task.java +++ b/src/bindings/java/org/simgrid/msg/Task.java @@ -161,17 +161,19 @@ public class Task { /** Cancels a task. */ public native void cancel(); - /** Deletes a task. - * - * @exception NativeException if the destruction failed. - */ - protected void finalize() throws NativeException { - destroy(); + /** Deletes a task once the garbage collector reclaims it */ + @Override + protected void finalize() { + try { + // Exceptions in finalizers lead to bad situations: + // http://stackoverflow.com/questions/7644556/troubleshooting-a-java-memory-leak-finalization + nativeFinalize(); + bind=0; // to avoid segfaults if the impossible happens yet again making this task surviving its finalize() + } catch (Throwable e) { + e.printStackTrace(); + } } - /** - * The natively implemented method to destroy a MSG task. - */ - protected native void destroy(); + protected native void nativeFinalize(); /* * * * * * Communication-related * * * * * */ diff --git a/src/bindings/java/org/simgrid/msg/VM.java b/src/bindings/java/org/simgrid/msg/VM.java index c6a522087f..77cdaeeb1b 100644 --- a/src/bindings/java/org/simgrid/msg/VM.java +++ b/src/bindings/java/org/simgrid/msg/VM.java @@ -73,9 +73,15 @@ public class VM extends Host{ } return null; } - protected void finalize() { - destroy(); + @Override + public void finalize() { + try { + nativeFinalize(); + } catch (Throwable e) { + e.printStackTrace(); + } } + private native void nativeFinalize(); /* JNI / Native code */ @@ -199,13 +205,6 @@ public class VM extends Host{ public native void restore(); - /** - * Destroy the VM - */ - public native void destroy(); - - - /** * Class initializer, to initialize various JNI stuff */ diff --git a/src/include/mc/datatypes.h b/src/include/mc/datatypes.h index 22c7e4f7dc..be00ce8fb9 100644 --- a/src/include/mc/datatypes.h +++ b/src/include/mc/datatypes.h @@ -11,8 +11,10 @@ #include "xbt/swag.h" #include "xbt/fifo.h" +#if HAVE_MC #include #include +#endif SG_BEGIN_DECL() diff --git a/src/mc/mc_request.cpp b/src/mc/mc_request.cpp index c3de6850aa..4d0ebf46c1 100644 --- a/src/mc/mc_request.cpp +++ b/src/mc/mc_request.cpp @@ -232,7 +232,7 @@ static char *buff_size_to_string(size_t buff_size) char *MC_request_to_string(smx_simcall_t req, int value, e_mc_request_type_t request_type) { - bool use_remote_comm = false; + bool use_remote_comm = true; switch(request_type) { case MC_REQUEST_SIMIX: use_remote_comm = true; @@ -473,7 +473,7 @@ unsigned int MC_request_testany_fail(smx_simcall_t req) for (cursor=0; cursor != comms.used; ++cursor) { // Get the element: - smx_synchro_t remote_action; + smx_synchro_t remote_action = NULL; memcpy(&remote_action, buffer + comms.elmsize * cursor, sizeof(remote_action)); // Dereference the pointer: diff --git a/src/mc/mc_unw_vmread.cpp b/src/mc/mc_unw_vmread.cpp index 55e348155b..a4e567771c 100644 --- a/src/mc/mc_unw_vmread.cpp +++ b/src/mc/mc_unw_vmread.cpp @@ -48,7 +48,6 @@ static int access_mem(const unw_addr_space_t as, { if (write) return - UNW_EINVAL; - ssize_t s; pid_t pid = _UPT_getpid(arg); size_t size = sizeof(unw_word_t); @@ -58,7 +57,7 @@ static int access_mem(const unw_addr_space_t as, struct iovec local = { valp, size }; struct iovec remote = { (void*) addr, size }; - s = process_vm_readv(pid, &local, 1, &remote, 1, 0); + ssize_t s = process_vm_readv(pid, &local, 1, &remote, 1, 0); if (s >= 0) { if ((size_t) s != size) return - UNW_EINVAL; diff --git a/src/simix/libsmx.c b/src/simix/libsmx.c index 4ed7355718..9a182a1525 100644 --- a/src/simix/libsmx.c +++ b/src/simix/libsmx.c @@ -739,7 +739,7 @@ void simcall_process_set_kill_time(smx_process_t process, double kill_time) if (simix_global->kill_process_function) { XBT_DEBUG("Set kill time %f for process %s(%s)",kill_time, process->name, sg_host_name(process->smx_host)); - SIMIX_timer_set(kill_time, simix_global->kill_process_function, process); + process->kill_timer = SIMIX_timer_set(kill_time, simix_global->kill_process_function, process); } } } diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index 43b0787a3b..afbc67c16b 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -514,7 +514,7 @@ void SIMIX_run(void) * \param arg Parameters of the function * */ -XBT_INLINE void SIMIX_timer_set(double date, void *function, void *arg) +XBT_INLINE smx_timer_t SIMIX_timer_set(double date, void *function, void *arg) { smx_timer_t timer = xbt_new0(s_smx_timer_t, 1); @@ -522,6 +522,16 @@ XBT_INLINE void SIMIX_timer_set(double date, void *function, void *arg) timer->func = function; timer->args = arg; xbt_heap_push(simix_timers, timer, date); + return timer; +} +/** @brief cancels a timer that was added earlier */ +XBT_INLINE void SIMIX_timer_remove(smx_timer_t timer) { + xbt_heap_rm_elm(simix_timers, timer, timer->date); +} + +/** @brief Returns the date at which the timer will trigger (or 0 if NULL timer) */ +XBT_INLINE double SIMIX_timer_get_date(smx_timer_t timer) { + return timer?timer->date:0; } /** diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index 8771f6ed32..21a4ef8eb9 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -50,6 +50,10 @@ void SIMIX_process_cleanup(smx_process_t process) SIMIX_process_on_exit_runall(process); + /* Unregister from the kill timer if any */ + if (process->kill_timer != NULL) + SIMIX_timer_remove(process->kill_timer); + /* cancel non-blocking communications */ smx_synchro_t synchro; while ((synchro = xbt_fifo_pop(process->comms))) { @@ -158,7 +162,7 @@ void SIMIX_process_stop(smx_process_t arg) { if (arg->auto_restart && !SIMIX_host_get_state(arg->smx_host)) { SIMIX_host_add_auto_restart_process(arg->smx_host,arg->name,arg->code, arg->data, sg_host_name(arg->smx_host), - arg->kill_time, + SIMIX_timer_get_date(arg->kill_timer), arg->argc,arg->argv,arg->properties, arg->auto_restart); } @@ -261,7 +265,6 @@ void SIMIX_process_create(smx_process_t *process, (*process)->code = code; (*process)->argc = argc; (*process)->argv = argv; - (*process)->kill_time = kill_time; XBT_VERB("Create context %s", (*process)->name); @@ -291,7 +294,7 @@ void SIMIX_process_create(smx_process_t *process, if (kill_time > SIMIX_get_clock() && simix_global->kill_process_function) { XBT_DEBUG("Process %s(%s) will be kill at time %f", (*process)->name, sg_host_name((*process)->smx_host), kill_time); - SIMIX_timer_set(kill_time, simix_global->kill_process_function, *process); + (*process)->kill_timer = SIMIX_timer_set(kill_time, simix_global->kill_process_function, *process); } } } @@ -953,18 +956,15 @@ void SIMIX_process_auto_restart_set(smx_process_t process, int auto_restart) { smx_process_t simcall_HANDLER_process_restart(smx_simcall_t simcall, smx_process_t process) { return SIMIX_process_restart(process, simcall->issuer); } -/** - * \brief Restart a process. - * Restart a process, starting it again from the beginning. - */ +/** @brief Restart a process, starting it again from the beginning. */ smx_process_t SIMIX_process_restart(smx_process_t process, smx_process_t issuer) { XBT_DEBUG("Restarting process %s on %s", process->name, sg_host_name(process->smx_host)); //retrieve the arguments of the old process - //FIXME: Factorise this with SIMIX_host_add_auto_restart_process ? + //FIXME: Factorize this with SIMIX_host_add_auto_restart_process ? s_smx_process_arg_t arg; arg.code = process->code; arg.hostname = sg_host_name(process->smx_host); - arg.kill_time = process->kill_time; + arg.kill_time = SIMIX_timer_get_date(process->kill_timer); arg.argc = process->argc; arg.data = process->data; int i; diff --git a/src/simix/smx_process_private.h b/src/simix/smx_process_private.h index 8b4f8ed9ba..b3cd4bcede 100644 --- a/src/simix/smx_process_private.h +++ b/src/simix/smx_process_private.h @@ -58,8 +58,7 @@ typedef struct s_smx_process { xbt_main_func_t code; int argc; char **argv; - double kill_time; - + smx_timer_t kill_timer; } s_smx_process_t; diff --git a/src/xbt/heap.c b/src/xbt/heap.c index 34b12cc593..f2f75bab0f 100644 --- a/src/xbt/heap.c +++ b/src/xbt/heap.c @@ -108,7 +108,6 @@ void xbt_heap_push(xbt_heap_t H, void *content, double key) return; } - /** * @brief Extracts from the heap and returns the element with the smallest key. * \param H the heap we're working on @@ -169,6 +168,19 @@ void *xbt_heap_remove(xbt_heap_t H, int i) return xbt_heap_pop(H); } +/** @brief Remove an arbitrary element from the heap + * @param H the heap we're working on + * @param content the object you want to add to the heap + * @param key the key associated to this object + */ +void xbt_heap_rm_elm(xbt_heap_t H, void *content, double key) { + int i=0; + while (i < H->count && (KEY(H, i) != key || CONTENT(H, i) != content)) + i++; + if (i == H->count) + return; + xbt_heap_remove(H,i); +} /** * @brief Updates an element of the heap with a new value.