From 838d182d3af0dbb5d77bde6eeffd6e322ebe4aa9 Mon Sep 17 00:00:00 2001 From: mquinson Date: Fri, 26 Nov 2010 21:44:41 +0000 Subject: [PATCH 1/1] reduce the coupling between main lib and java binding git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@8691 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/java/jmsg.c | 34 +++++------------------------ src/java/jmsg.h | 3 --- src/java/simgrid/msg/MsgNative.java | 5 +---- src/simix/smx_context.c | 10 +-------- 4 files changed, 7 insertions(+), 45 deletions(-) diff --git a/src/java/jmsg.c b/src/java/jmsg.c index 43dc519e28..b44b39ff43 100644 --- a/src/java/jmsg.c +++ b/src/java/jmsg.c @@ -803,6 +803,9 @@ Java_simgrid_msg_Msg_getClock(JNIEnv * env, jclass cls) return (jdouble) MSG_get_clock(); } +/*Hack: let msg load directly the right factory */ +typedef void (*SIMIX_ctx_factory_initializer_t)(smx_context_factory_t *); +extern SIMIX_ctx_factory_initializer_t factory_initializer_to_use; JNIEXPORT void JNICALL Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) @@ -813,6 +816,8 @@ Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) jstring jval; const char *tmp; + factory_initializer_to_use = SIMIX_ctx_java_factory_init; + if (jargs) argc = (int) (*env)->GetArrayLength(env, jargs); @@ -828,7 +833,6 @@ Java_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) } MSG_global_init(&argc, argv); - SIMIX_context_select_factory("java"); for (index = 0; index < argc; index++) free(argv[index]); @@ -960,34 +964,6 @@ Java_simgrid_msg_MsgNative_allHosts(JNIEnv * env, jclass cls_arg) return jtable; } - -JNIEXPORT void JNICALL -Java_simgrid_msg_MsgNative_selectContextFactory(JNIEnv * env, jclass class, - jstring jname) -{ - char *errmsg = NULL; - xbt_ex_t e; - - /* get the C string from the java string */ - const char *name = (*env)->GetStringUTFChars(env, jname, 0); - - TRY { - SIMIX_context_select_factory(name); - } CATCH(e) { - errmsg = xbt_strdup(e.msg); - xbt_ex_free(e); - } - - (*env)->ReleaseStringUTFChars(env, jname, name); - - if (errmsg) { - char *thrown = - bprintf("xbt_select_context_factory() failed: %s", errmsg); - free(errmsg); - jxbt_throw_jni(env, thrown); - } -} - JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_taskSend(JNIEnv * env, jclass cls, jstring jalias, jobject jtask, diff --git a/src/java/jmsg.h b/src/java/jmsg.h index c6ff810748..dffe8b987f 100644 --- a/src/java/jmsg.h +++ b/src/java/jmsg.h @@ -323,9 +323,6 @@ JNIEXPORT void JNICALL Java_simgrid_msg_Msg_createEnvironment(JNIEnv * env, jclass cls, jstring jplatformFile); -JNIEXPORT void JNICALL -Java_simgrid_msg_MsgNative_selectContextFactory(JNIEnv *, jclass, jstring); - JNIEXPORT void JNICALL Java_simgrid_msg_MsgNative_taskSendBounded(JNIEnv *, jclass, jstring, jobject, jdouble); diff --git a/src/java/simgrid/msg/MsgNative.java b/src/java/simgrid/msg/MsgNative.java index 973e4df289..e7f7759a2d 100644 --- a/src/java/simgrid/msg/MsgNative.java +++ b/src/java/simgrid/msg/MsgNative.java @@ -18,9 +18,6 @@ package simgrid.msg; */ final class MsgNative { - final static native - void selectContextFactory(String name) throws NativeException; - /****************************************************************** * The natively implemented methods connected to the MSG Process * ******************************************************************/ @@ -428,4 +425,4 @@ final class MsgNative { */ final static native void taskSendBounded(String alias, Task task, double maxrate) throws TransferFailureException,HostFailureException,TimeoutException; -} \ No newline at end of file +} diff --git a/src/simix/smx_context.c b/src/simix/smx_context.c index 15772ca4fc..59638fa518 100644 --- a/src/simix/smx_context.c +++ b/src/simix/smx_context.c @@ -84,15 +84,7 @@ int SIMIX_context_select_factory(const char *name) /* init the desired factory */ smx_context_factory_t * factory = &simix_global->context_factory; - if (!strcmp(name, "java")) -#ifdef HAVE_JAVA - SIMIX_ctx_java_factory_init(factory); -#else - THROW0(not_found_error, 0, - "Factory 'Java' does not exist: Java support was not compiled in the SimGrid library"); -#endif /* HAVE_JAVA */ - - else if (!strcmp(name, "thread")) + if (!strcmp(name, "thread")) #ifdef CONTEXT_THREADS SIMIX_ctx_thread_factory_init(factory); #else -- 2.20.1