Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'v3_9_x'
[simgrid.git] / src / smx_context_cojava.c
index 42c655e..00fe9b5 100644 (file)
@@ -83,6 +83,7 @@ void SIMIX_ctx_cojava_factory_init(smx_context_factory_t * factory)
 
   jclass class_thread = (*global_env)->FindClass(global_env, "java/lang/Thread");
   xbt_assert((class_thread != NULL), "Can't find java.lang.Thread class");
+  
   jclass class_coroutine_support = (*global_env)->FindClass(global_env, "java/dyn/CoroutineSupport");
   xbt_assert((class_coroutine_support != NULL), "Can't find java.dyn.CoroutineSupport class");
   jmethodID thread_get_current = (*global_env)->GetStaticMethodID(global_env, class_thread, "currentThread", "()Ljava/lang/Thread;");
@@ -244,10 +245,12 @@ static void smx_ctx_cojava_runall(void)
 {
   cojava_processes = SIMIX_process_get_runnable();
   smx_process_t process;
-  process = xbt_dynar_get_as(cojava_processes, 0, smx_process_t);
-  cojava_process_index = 1;
-  /* Execute the first process */
-  smx_ctx_cojava_resume(SIMIX_process_get_context(process));
+  if (xbt_dynar_length(cojava_processes) > 0) {
+    process = xbt_dynar_get_as(cojava_processes, 0, smx_process_t);
+    cojava_process_index = 1;
+    /* Execute the first process */
+    smx_ctx_cojava_resume(SIMIX_process_get_context(process));
+  }
 }
 
 static void smx_ctx_cojava_create_coroutine(smx_ctx_cojava_t context) {
@@ -255,7 +258,24 @@ static void smx_ctx_cojava_create_coroutine(smx_ctx_cojava_t context) {
   jclass coclass = (*env)->FindClass(env, "java/dyn/Coroutine");
   xbt_assert((coclass != NULL), "Can't find coroutine class ! :(");
   jobject jcoroutine = (*env)->NewObject(env, coclass, coroutine_init, context->jprocess);
-  xbt_assert((jcoroutine != NULL), "Can't create coroutine object.");
+  if (jcoroutine == NULL) {
+     FILE *conf= fopen("/proc/sys/vm/max_map_count","r");
+     if (conf) {
+       int limit=-1;
+       fscanf(conf,"%d",&limit);
+       fclose(conf);
+       if (limit!=-1 && SIMIX_process_count() > (limit - 100) /2)
+          xbt_die("Error while creating a new coroutine. "
+                  "This seem due to the the vm.max_map_count system limit that is only equal to %d while we already have %d coroutines. "
+                  "Please check the install documentation to see how to increase this limit", limit, SIMIX_process_count());
+       if (limit == -1)
+         xbt_die("Error while creating a new coroutine. "
+                 "This seems to be a non-linux system, disabling the automatic verification that the system limit on the amount of memory maps is high enough.");
+       xbt_die("Error while creating a new coroutine. ");
+     }
+     
+  }
+   
   jcoroutine = (*env)->NewGlobalRef(env, jcoroutine);
   context->jcoroutine = jcoroutine;
 }