# Declare our package content #
###############################
set(JMSG_C_SRC
+ src/smx_context_cojava.h
+ src/smx_context_cojava.c
src/smx_context_java.h
src/smx_context_java.c
src/jxbt_utilities.c
catch(ProcessKilledError pk) {
}
+ exit();
}
/**
*/
public abstract void main(String[]args) throws MsgException;
-
+ public native void exit();
/**
* Class initializer, to initialize various JNI stuff
*/
*/
public native void resetNextSubstream();
/**
- * If a = true the stream g will start generating antithetic variates, i.e., 1 − U instead of U , until
+ * If a = true the stream g will start generating antithetic variates, i.e., 1 - U instead of U , until
* this method is called again with a = false.
*/
public native void setAntithetic(boolean a);
#include <locale.h>
#include "smx_context_java.h"
+#include "smx_context_cojava.h"
#include "jmsg_process.h"
(*env)->GetJavaVM(env, &__java_vm);
- smx_factory_initializer_to_use = SIMIX_ctx_java_factory_init;
+ if ((*env)->FindClass(env, "java/dyn/Coroutine")) {
+ XBT_VERB("Using Coroutines");
+ smx_factory_initializer_to_use = SIMIX_ctx_cojava_factory_init;
+ }
+ else {
+ XBT_VERB("Using java threads");
+ smx_factory_initializer_to_use = SIMIX_ctx_java_factory_init;
+ }
+ jthrowable exc = (*env)->ExceptionOccurred(env);
+ if (exc) {
+ (*env)->ExceptionClear(env);
+ }
setlocale(LC_NUMERIC,"C");
/* sets the PID and the PPID of the process */
(*env)->SetIntField(env, jprocess, jprocess_field_Process_pid,(jint) MSG_process_get_PID(process));
(*env)->SetIntField(env, jprocess, jprocess_field_Process_ppid, (jint) MSG_process_get_PPID(process));
-
jprocess_bind(jprocess, process, env);
return 0;
#include "jmsg_host.h"
#include "jxbt_utilities.h"
#include "smx_context_java.h"
+#include "smx_context_cojava.h"
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_exit(JNIEnv *env, jobject jprocess) {
+ if (smx_factory_initializer_to_use == SIMIX_ctx_cojava_factory_init) {
+ m_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(m_process_t process)
{
return ((smx_ctx_java_t)MSG_process_get_smx_ctx(process))->jprocess;
/* change the host java side */
(*env)->SetObjectField(env, jprocess, jprocess_field_Process_host, jhost);
}
+
+
+
jfieldID jprocess_field_Process_pid;
jfieldID jprocess_field_Process_ppid;
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_exit(JNIEnv *env, jobject);
+
jobject native_to_java_process(m_process_t process);
*/
JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_migrate
(JNIEnv *, jobject, jobject);
+
#endif /* !MSG_JPROCESS_H */
if (!jtask_field_Task_bind || !jtask_class_Task || !jtask_field_Comm_bind || !jtask_field_Comm_taskBind ||
!jtask_field_Comm_receiving || !jtask_method_Comm_constructor) {
jxbt_throw_native(env,bprintf("Can't find some fields in Java class."));
- }
+ }
}
JNIEXPORT void JNICALL
jobject jhost)
{
MSG_error_t rv;
- m_task_t task = NULL;
+ m_task_t *task = xbt_new(m_task_t,1);
+ *task = NULL;
+
m_host_t host = NULL;
jobject jtask_global, jtask_local;
const char *alias;
alias = (*env)->GetStringUTFChars(env, jalias, 0);
TRY {
- rv = MSG_task_receive_ext(&task, alias, (double) jtimeout, host);
+ rv = MSG_task_receive_ext(task, alias, (double) jtimeout, host);
}
CATCH_ANONYMOUS {
return NULL;
jmsg_throw_status(env,rv);
return NULL;
}
- jtask_global = MSG_task_get_data(task);
+ jtask_global = MSG_task_get_data(*task);
/* Convert the global ref into a local ref so that the JVM can free the stuff */
jtask_local = (*env)->NewLocalRef(env, jtask_global);
(*env)->DeleteGlobalRef(env, jtask_global);
- MSG_task_set_data(task, NULL);
+ MSG_task_set_data(*task, NULL);
(*env)->ReleaseStringUTFChars(env, jalias, alias);
+ xbt_free(task);
+
jxbt_check_res("MSG_task_receive_ext()", rv,
MSG_HOST_FAILURE | MSG_TRANSFER_FAILURE | MSG_TIMEOUT,
bprintf("while receiving from mailbox %s", alias));
-/* Copyright (c) 2009, 2010. The SimGrid Team.
+/* Copyright (c) 2009, 2010, 2012. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it