From eb72021a43c03453941437148607e47c7a3d45a2 Mon Sep 17 00:00:00 2001 From: Samuel Lepetit Date: Fri, 18 May 2012 14:03:57 +0200 Subject: [PATCH 1/1] Fix the handling of errors in Task.send --- org/simgrid/msg/Comm.java | 4 ++-- src/jmsg.c | 18 ++++++++++++++++++ src/jmsg.h | 7 ++++++- src/jmsg_comm.c | 23 +++++------------------ src/jmsg_comm.h | 7 +------ src/jmsg_task.c | 22 +++++----------------- 6 files changed, 37 insertions(+), 44 deletions(-) diff --git a/org/simgrid/msg/Comm.java b/org/simgrid/msg/Comm.java index bd84cb5671..3ef08e34e7 100644 --- a/org/simgrid/msg/Comm.java +++ b/org/simgrid/msg/Comm.java @@ -41,12 +41,12 @@ public class Comm { * Finalize the communication object, destroying it. */ protected void finalize() throws Throwable { - unbind(); + destroy(); } /** * Unbind the communication object */ - public native void unbind() throws NativeException; + public native void destroy() throws NativeException; /** * Returns if the communication is finished or not. * If the communication has finished and there was an error, diff --git a/src/jmsg.c b/src/jmsg.c index 1e02578f40..ee091f2e9e 100644 --- a/src/jmsg.c +++ b/src/jmsg.c @@ -49,6 +49,24 @@ JNIEnv *get_current_thread_env(void) (*__java_vm)->AttachCurrentThread(__java_vm, (void **) &env, NULL); return env; } + +void jmsg_throw_status(JNIEnv *env, MSG_error_t status) { + switch (status) { + case MSG_TIMEOUT: + jxbt_throw_time_out_failure(env,NULL); + break; + case MSG_TRANSFER_FAILURE: + jxbt_throw_transfer_failure(env,NULL); + break; + case MSG_HOST_FAILURE: + jxbt_throw_host_failure(env,NULL); + break; + default: + jxbt_throw_native(env,bprintf("communication failed")); + } +} + + /*************************************************************************************** * Unsortable functions * ***************************************************************************************/ diff --git a/src/jmsg.h b/src/jmsg.h index c943fe6ef3..da58d25eaf 100644 --- a/src/jmsg.h +++ b/src/jmsg.h @@ -8,12 +8,17 @@ #ifndef MSG4JAVA_H #define MSG4JAVA_H - +#include #include JavaVM *get_java_VM(void); JNIEnv *get_current_thread_env(void); +/** + * This function throws the correct exception according to the status + * provided. + */ +void jmsg_throw_status(JNIEnv *env, MSG_error_t status); /* * Class org_simgrid_msg_Msg diff --git a/src/jmsg_comm.c b/src/jmsg_comm.c index 4a394cd3f4..48638c04c0 100644 --- a/src/jmsg_comm.c +++ b/src/jmsg_comm.c @@ -3,6 +3,8 @@ /* Copyright (c) 2012. The SimGrid Team. All rights reserved. */ #include "jmsg_comm.h" #include "jxbt_utilities.h" +#include "jmsg.h" + #include XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg); @@ -35,21 +37,6 @@ void jcomm_bind_task(JNIEnv *env, jobject jcomm) { } } -void jcomm_throw(JNIEnv *env, MSG_error_t status) { - switch (status) { - case MSG_TIMEOUT: - jxbt_throw_time_out_failure(env,NULL); - break; - case MSG_TRANSFER_FAILURE: - jxbt_throw_transfer_failure(env,NULL); - break; - case MSG_HOST_FAILURE: - jxbt_throw_host_failure(env,NULL); - break; - default: - jxbt_throw_native(env,bprintf("communication failed")); - } -} JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_nativeInit(JNIEnv *env, jclass cls) { @@ -68,7 +55,7 @@ Java_org_simgrid_msg_Comm_nativeInit(JNIEnv *env, jclass cls) { } JNIEXPORT void JNICALL -Java_org_simgrid_msg_Comm_unbind(JNIEnv *env, jobject jcomm) { +Java_org_simgrid_msg_Comm_destroy(JNIEnv *env, jobject jcomm) { msg_comm_t comm; m_task_t *task_received; @@ -97,7 +84,7 @@ Java_org_simgrid_msg_Comm_test(JNIEnv *env, jobject jcomm) { } else { //send the correct exception - jcomm_throw(env,status); + jmsg_throw_status(env,status); return JNI_FALSE; } } @@ -129,7 +116,7 @@ Java_org_simgrid_msg_Comm_waitCompletion(JNIEnv *env, jobject jcomm, jdouble tim return; } else { - jcomm_throw(env,status); + jmsg_throw_status(env,status); } diff --git a/src/jmsg_comm.h b/src/jmsg_comm.h index 2c70d392f2..ce86f9d468 100644 --- a/src/jmsg_comm.h +++ b/src/jmsg_comm.h @@ -11,17 +11,12 @@ * the java communication object. */ void jcomm_bind_task(JNIEnv *env, jobject jcomm); -/** - * This function throws the correct exception according to the status - * returned. - */ -void jcomm_throw(JNIEnv *env, MSG_error_t status); JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_nativeInit(JNIEnv *env, jclass cls); JNIEXPORT void JNICALL -Java_org_simgrid_msg_Comm_unbind(JNIEnv *env, jobject jcomm); +Java_org_simgrid_msg_Comm_destroy(JNIEnv *env, jobject jcomm); JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Comm_test(JNIEnv *env, jobject jcomm); diff --git a/src/jmsg_task.c b/src/jmsg_task.c index 86fe919ab6..9eb973c9f6 100644 --- a/src/jmsg_task.c +++ b/src/jmsg_task.c @@ -367,10 +367,10 @@ Java_org_simgrid_msg_Task_send(JNIEnv * env,jobject jtask, (*env)->ReleaseStringUTFChars(env, jalias, alias); - jxbt_check_res("MSG_task_send_with_timeout()", rv, - MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT, - bprintf("while sending task %s to mailbox %s", - MSG_task_get_name(task), alias)); + if (rv != MSG_OK) { + jmsg_throw_status(env, rv); + return; + } } JNIEXPORT void JNICALL @@ -432,19 +432,7 @@ Java_org_simgrid_msg_Task_receive(JNIEnv * env, jclass cls, return NULL; } if (rv != MSG_OK) { - switch (rv) { - case MSG_TIMEOUT: - jxbt_throw_time_out_failure(env,NULL); - break; - case MSG_TRANSFER_FAILURE: - jxbt_throw_transfer_failure(env,NULL); - break; - case MSG_HOST_FAILURE: - jxbt_throw_host_failure(env,NULL); - break; - default: - jxbt_throw_native(env,bprintf("receive failed")); - } + jmsg_throw_status(env,rv); return NULL; } jtask_global = MSG_task_get_data(task); -- 2.20.1