コード例 #1
0
ファイル: jmsg.cpp プロジェクト: oar-team/simgrid-batsim
/** Run the Java org.simgrid.msg.Process */
void java_main_jprocess(jobject jprocess)
{
  JNIEnv *env = get_current_thread_env();
  simgrid::java::JavaContext* context = (simgrid::java::JavaContext*) SIMIX_context_self();
  context->jprocess = jprocess;
  smx_process_t process = SIMIX_process_self();
  jprocess_bind(context->jprocess, process, env);

  // Adrien, ugly path, just to bypass creation of context at low levels (i.e such as for the VM migration for instance)
  if (context->jprocess == nullptr)
    return;
  else
    run_jprocess(env, context->jprocess);
}
コード例 #2
0
ファイル: ContextRaw.cpp プロジェクト: luizabeltrame/simgrid
void RawContext::resume_parallel()
{
#if HAVE_THREAD_CONTEXTS
  uintptr_t worker_id = __sync_fetch_and_add(&raw_threads_working, 1);
  xbt_os_thread_set_specific(raw_worker_id_key, (void*) worker_id);
  RawContext* worker_context = (RawContext*) SIMIX_context_self();
  raw_workers_context[worker_id] = worker_context;
  XBT_DEBUG("Saving worker stack %zu", worker_id);
  SIMIX_context_set_current(this);
  raw_swapcontext(&worker_context->stack_top_, this->stack_top_);
#else
  xbt_die("Parallel execution disabled");
#endif
}
コード例 #3
0
ファイル: BoostContext.cpp プロジェクト: RockyMeadow/simgrid
void BoostParallelContext::resume()
{
  unsigned long worker_id = __sync_fetch_and_add(&threads_working_, 1);
  xbt_os_thread_set_specific(worker_id_key_, (void*) worker_id);

  BoostParallelContext* worker_context =
    static_cast<BoostParallelContext*>(SIMIX_context_self());
  workers_context_[worker_id] = worker_context;

  SIMIX_context_set_current(this);
#if HAVE_BOOST_CONTEXTS == 1
  boost::context::jump_fcontext(
    worker_context->fc_, this->fc_, (intptr_t) this);
#else
  boost::context::jump_fcontext(
    &worker_context->fc_, this->fc_, (intptr_t) this);
#endif
}
コード例 #4
0
static void smx_ctx_boost_resume_parallel(smx_process_t process)
{
  unsigned long worker_id = __sync_fetch_and_add(&boost_threads_working, 1);
  xbt_os_thread_set_specific(boost_worker_id_key, (void*) worker_id);

  smx_ctx_boost_t worker_context = (smx_ctx_boost_t)SIMIX_context_self();
  boost_workers_context[worker_id] = worker_context;
  smx_ctx_boost_t context = (smx_ctx_boost_t) process->context;

  SIMIX_context_set_current((smx_context_t) context);
#if HAVE_BOOST_CONTEXT == 1
  boost::context::jump_fcontext(worker_context->fc, context->fc,
    (intptr_t)context);
#else
  boost::context::jump_fcontext(&worker_context->fc, context->fc,
    (intptr_t)context);
#endif
}
コード例 #5
0
ファイル: jmsg.cpp プロジェクト: oar-team/simgrid-batsim
/** Create a Java org.simgrid.msg.Process with the arguments and run it */
static int java_main(int argc, char *argv[])
{
  JNIEnv *env = get_current_thread_env();
  simgrid::java::JavaContext* context = (simgrid::java::JavaContext*) SIMIX_context_self();

  //Change the "." in class name for "/".
  xbt_str_subst(argv[0],'.','/',0);
  jclass class_Process = env->FindClass(argv[0]);
  xbt_str_subst(argv[0],'/','.',0);
  //Retrieve the methodID for the constructor
  xbt_assert((class_Process != nullptr), "Class not found (%s). The deployment file must use the fully qualified class name, including the package. The case is important.", argv[0]);
  jmethodID constructor_Process = env->GetMethodID(class_Process, "<init>", "(Lorg/simgrid/msg/Host;Ljava/lang/String;[Ljava/lang/String;)V");
  xbt_assert((constructor_Process != nullptr), "Constructor not found for class %s. Is there a (Host, String ,String[]) constructor in your class ?", argv[0]);

  //Retrieve the name of the process.
  jstring jname = env->NewStringUTF(argv[0]);
  //Build the arguments
  jobjectArray args = (jobjectArray)env->NewObjectArray(argc - 1,
    env->FindClass("java/lang/String"),
    env->NewStringUTF(""));
  int i;
  for (i = 1; i < argc; i++)
      env->SetObjectArrayElement(args,i - 1, env->NewStringUTF(argv[i]));
  //Retrieve the host for the process.
  jstring jhostName = env->NewStringUTF(MSG_host_get_name(MSG_host_self()));
  jobject jhost = Java_org_simgrid_msg_Host_getByName(env, nullptr, jhostName);
  //creates the process
  jobject jprocess = env->NewObject(class_Process, constructor_Process, jhost, jname, args);
  xbt_assert((jprocess != nullptr), "Process allocation failed.");
  jprocess = env->NewGlobalRef(jprocess);
  //bind the process to the context
  msg_process_t process = MSG_process_self();

  context->jprocess = jprocess;
  /* sets the PID and the PPID of the process */
  env->SetIntField(jprocess, jprocess_field_Process_pid,(jint) MSG_process_get_PID(process));
  env->SetIntField(jprocess, jprocess_field_Process_ppid, (jint) MSG_process_get_PPID(process));
  jprocess_bind(jprocess, process, env);

  run_jprocess(env, context->jprocess);
  return 0;
}