X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/1283307f26e739e654d195f81cceee5ce1683d99..8d5eb75ca43a7d072ab9d0ef84a0b409139321ba:/src/bindings/java/jmsg_process.c?ds=sidebyside diff --git a/src/bindings/java/jmsg_process.c b/src/bindings/java/jmsg_process.c index aaa73e70ef..a7b3a3fb94 100644 --- a/src/bindings/java/jmsg_process.c +++ b/src/bindings/java/jmsg_process.c @@ -1,27 +1,31 @@ /* Functions related to the java process instances. */ -/* Copyright (c) 2007-2012. The SimGrid Team. +/* Copyright (c) 2007-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. */ + * under the terms of the license (GNU LGPL) which comes with this package. */ + #include "jmsg_process.h" #include "jmsg.h" #include "jmsg_host.h" #include "jxbt_utilities.h" #include "smx_context_java.h" -#include "smx_context_cojava.h" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg); +jfieldID jprocess_field_Process_bind; +jfieldID jprocess_field_Process_host; +jfieldID jprocess_field_Process_killTime; +jfieldID jprocess_field_Process_id; +jfieldID jprocess_field_Process_name; +jfieldID jprocess_field_Process_pid; +jfieldID jprocess_field_Process_ppid; + JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_exit(JNIEnv *env, jobject jprocess) { - if (smx_factory_initializer_to_use == SIMIX_ctx_cojava_factory_init) { - msg_process_t process = jprocess_to_native_process(jprocess, env); - smx_context_t context = MSG_process_get_smx_ctx(process); - smx_ctx_cojava_stop(context); - } + } jobject native_to_java_process(msg_process_t process) @@ -48,17 +52,21 @@ void jprocess_join(jobject jprocess, JNIEnv * env) msg_process_t jprocess_to_native_process(jobject jprocess, JNIEnv * env) { - return (msg_process_t) (long) (*env)->GetLongField(env, jprocess, jprocess_field_Process_bind); + return + (msg_process_t)(intptr_t)(*env)->GetLongField(env, jprocess, + jprocess_field_Process_bind); } void jprocess_bind(jobject jprocess, msg_process_t process, JNIEnv * env) { - (*env)->SetLongField(env, jprocess, jprocess_field_Process_bind, (jlong)(process)); + (*env)->SetLongField(env, jprocess, jprocess_field_Process_bind, + (intptr_t)process); } jlong jprocess_get_id(jobject jprocess, JNIEnv * env) { - return (*env)->GetLongField(env, jprocess, jprocess_field_Process_id); + return + (intptr_t)(*env)->GetLongField(env, jprocess, jprocess_field_Process_id); } jstring jprocess_get_name(jobject jprocess, JNIEnv * env) @@ -118,9 +126,9 @@ Java_org_simgrid_msg_Process_create(JNIEnv * env, } /* bind/retrieve the msg host */ - host = MSG_get_host_by_name(hostname); + host = MSG_host_by_name(hostname); - if (!(host)) { /* not binded */ + if (!(host)) { /* not bound */ jxbt_throw_host_not_found(env, hostname); return; } @@ -212,7 +220,7 @@ Java_org_simgrid_msg_Process_getProperty(JNIEnv *env, jobject jprocess, jobject return jproperty; } JNIEXPORT jobject JNICALL -Java_org_simgrid_msg_Process_currentProcess(JNIEnv * env, jclass cls) +Java_org_simgrid_msg_Process_getCurrentProcess(JNIEnv * env, jclass cls) { msg_process_t process = MSG_process_self(); jobject jprocess; @@ -321,21 +329,22 @@ Java_org_simgrid_msg_Process_isSuspended(JNIEnv * env, } JNIEXPORT void JNICALL -Java_org_simgrid_msg_Process_sleep - (JNIEnv *env, jclass cls, jlong jmillis, jint jnanos) { - - double time = jmillis / 1000 + jnanos / 1000; - msg_error_t rv; - xbt_ex_t e; - TRY { - rv = MSG_process_sleep(time); - } - CATCH(e) { - xbt_ex_free(e); - return; - } +Java_org_simgrid_msg_Process_sleep(JNIEnv *env, jclass cls, jlong jmillis, jint jnanos) + { + double time = ((double)jmillis) / 1000 + ((double)jnanos) / 1000000000; + msg_error_t rv; + rv = MSG_process_sleep(time); if (rv != MSG_OK) { - jmsg_throw_status(env,rv); + XBT_DEBUG("Something during the MSG_process_sleep invocation was wrong, trigger a HostFailureException"); + + //jmsg_throw_status(env,rv); + + // adsein, the code above as been replaced by the code below. Indeed, according to the documentation, a sleep can only + // trigger a host_failure exception. When the sleep crashes due to a host shutdown, the exception thrown by smx_context_java.c + // is a cancelled_error, see bindings/java/smx_context_java.c, function void smx_ctx_java_stop(smx_context_t context) and src/msg/msg_gos.c + // function msg_error_t MSG_process_sleep(double nb_sec) + + jxbt_throw_host_failure(env,NULL); } } JNIEXPORT void JNICALL @@ -343,17 +352,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(e) { - xbt_ex_free(e); - return; - } + rv = MSG_process_sleep((double)jseconds); + if ((*env)->ExceptionOccurred(env)) + return; if (rv != MSG_OK) { - XBT_INFO("Status NOK"); - jmsg_throw_status(env,rv); + XBT_DEBUG("Status NOK"); + jmsg_throw_status(env,rv); } } @@ -392,6 +396,7 @@ Java_org_simgrid_msg_Process_migrate(JNIEnv * env, msg_error_t rv = MSG_process_migrate(process, host); if (rv != MSG_OK) { jmsg_throw_status(env,rv); + return; } /* change the host java side */ (*env)->SetObjectField(env, jprocess, jprocess_field_Process_host, jhost); @@ -404,12 +409,5 @@ Java_org_simgrid_msg_Process_setKillTime (JNIEnv *env , jobject jprocess, jdoubl JNIEXPORT jint JNICALL Java_org_simgrid_msg_Process_getCount(JNIEnv * env, jclass cls) { - /* FIXME: the next test on SimGrid version is to ensure that this still compiles with SG 3.8 while the C function were added in SG 3.9 only. - * This kind of pimple becomes mandatory when you get so slow to release the java version that it begins evolving further after the C release date. - */ -#if SIMGRID_VERSION >= 30900 return (jint) MSG_process_get_number(); -#else - return (jint) -1; -#endif }