Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
It may even work, soon
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 3 Dec 2010 00:16:55 +0000 (00:16 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 3 Dec 2010 00:16:55 +0000 (00:16 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/contrib/trunk/simgrid-java@8968 48e7efb5-ca39-0410-a469-dd3cf9ba447f

src/jmsg.c
src/jmsg_process.c
src/smx_context_java.c

index 62901c1..5becc9e 100644 (file)
@@ -6,8 +6,10 @@
 /* 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 "msg/msg.h"
-#include "simix/context.h"
+#include <msg/msg.h>
+#include <simix/context.h>
+#include <surf/surfxml_parse.h>
+
 #include "smx_context_java.h"
 
 #include "jmsg_process.h"
@@ -17,7 +19,6 @@
 #include "jxbt_utilities.h"
 
 #include "jmsg.h"
-#include "surf/surfxml_parse.h"
 
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
 
@@ -323,17 +324,17 @@ Java_simgrid_msg_MsgNative_hostGetByName(JNIEnv * env, jclass cls,
 
   /* get the C string from the java string */
   const char *name = (*env)->GetStringUTFChars(env, jname, 0);
-
+  DEBUG1("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);
-  DEBUG2("MSG gave %p as native host (simdata=%p)", host, host->simdata);
-
-  (*env)->ReleaseStringUTFChars(env, jname, name);
+  DEBUG2("MSG gave %p as native host (simdata=%p)", host,host? host->simdata:NULL);
 
   if (!host) {                  /* invalid name */
     jxbt_throw_host_not_found(env, name);
+    (*env)->ReleaseStringUTFChars(env, jname, name);
     return NULL;
   }
+  (*env)->ReleaseStringUTFChars(env, jname, name);
 
   if (!MSG_host_get_data(host)) {       /* native host not associated yet with java host */
 
@@ -814,15 +815,16 @@ JNIEXPORT void JNICALL
   jobject jhost;
 
   /* Run everything */
+  INFO0("Ready to run MSG_MAIN");
   rv = MSG_main();
+  INFO0("Done running MSG_MAIN");
   jxbt_check_res("MSG_main()", rv, MSG_OK,
                  bprintf
                  ("unexpected error : MSG_main() failed .. please report this bug "));
 
-  DEBUG0
-      ("MSG_main finished. Bail out before cleanup since there is a bug in this part.");
+  INFO0("MSG_main finished");
 
-  DEBUG0("Clean java world");
+  INFO0("Clean java world");
   /* Cleanup java hosts */
   hosts = MSG_get_host_table();
   for (index = 0; index < MSG_get_host_number() - 1; index++) {
@@ -832,7 +834,7 @@ JNIEXPORT void JNICALL
 
   }
 
-  DEBUG0("Clean native world");
+  INFO0("Clean native world");
   /* cleanup native stuff */
   rv = MSG_OK != MSG_clean();
   jxbt_check_res("MSG_clean()", rv, MSG_OK,
index 2a02b7f..a9dda6b 100644 (file)
@@ -189,10 +189,12 @@ void jprocess_schedule(smx_context_t context)
 
   env = get_current_thread_env();
 
-  id = jxbt_get_smethod(env, "simgrid/msg/Process", "schedule", "()V");
+  id = jxbt_get_smethod(env, "org/simgrid/msg/Process", "schedule", "()V");
 
-  if (!id)
+  if (!id) {
+    CRITICAL0("Cannot find java method org/simgrid/msg/Process/schedule()V");
     return;
+  }
 
   (*env)->CallVoidMethod(env, ((smx_ctx_java_t) context)->jprocess, id);
 }
index 781f490..0689627 100644 (file)
@@ -46,6 +46,7 @@ smx_ctx_java_factory_create_context(xbt_main_func_t code, int argc,
                                     void_pfn_smxprocess_t cleanup_func,
                                     void* data)
 {
+  fprintf(stderr,"XXXX Create Context\n");
   smx_ctx_java_t context = xbt_new0(s_smx_ctx_java_t, 1);
 
   /* If the user provided a function for the process then use it
@@ -86,6 +87,7 @@ static void smx_ctx_java_free(smx_context_t context)
 static void smx_ctx_java_stop(smx_context_t context)
 {
   jobject jprocess = NULL;
+  fprintf(stderr,"XXXX Context Stop\n");
 
   smx_ctx_java_t ctx_java;
 
@@ -94,8 +96,9 @@ static void smx_ctx_java_stop(smx_context_t context)
 
   ctx_java = (smx_ctx_java_t) context;
 
-  /*FIXME: is this really necessary? DIRTY HACK: let's comment it and see*/
-//  if (((smx_process_t)smx_current_context->data)->iwannadie) {
+  /*FIXME: is this really necessary? Seems to. */
+  if (smx_current_context->iwannadie) {
+    INFO0("I wannadie");
     /* The maestro call xbt_context_stop() with an exit code set to one */
     if (ctx_java->jprocess) {
       /* if the java process is alive schedule it */
@@ -108,32 +111,16 @@ static void smx_ctx_java_stop(smx_context_t context)
         jprocess_exit(jprocess, get_current_thread_env());
       }
     }
-//  } else {
+  } else {
     /* the java process exits */
-//    jprocess = ctx_java->jprocess;
-//    ctx_java->jprocess = NULL;
-//  }
+    jprocess = ctx_java->jprocess;
+    ctx_java->jprocess = NULL;
+  }
 
   /* delete the global reference associated with the java process */
   jprocess_delete_global_ref(jprocess, get_current_thread_env());
 }
 
-/*static void smx_ctx_java_swap(smx_context_t context)
-{
-  if (context) {
-    smx_context_t self = current_context;
-
-    current_context = context;
-
-    jprocess_schedule(context);
-
-    current_context = self;
-  }
-
-  if (current_context->iwannadie)
-    smx_ctx_java_stop(1);
-}*/
-
 static void smx_ctx_java_suspend(smx_context_t context)
 {
   jprocess_unschedule(context);
@@ -142,6 +129,7 @@ static void smx_ctx_java_suspend(smx_context_t context)
 // FIXME: inline those functions
 static void smx_ctx_java_resume(smx_context_t new_context)
 {
+  fprintf(stderr,"XXXX Context Resume\n");
   jprocess_schedule(new_context);
 }
 
@@ -149,11 +137,13 @@ static void smx_ctx_java_runall(xbt_swag_t processes)
 {
   smx_process_t process;
   smx_context_t old_context;
-  
+  fprintf(stderr,"XXXX Run all\n");
+
   while ((process = xbt_swag_extract(processes))) {
     old_context = smx_current_context;
     smx_current_context = SIMIX_process_get_context(process);
     smx_ctx_java_resume(smx_current_context);
     smx_current_context = old_context;
   }
+  fprintf(stderr,"XXXX End of run all\n");
 }