The gaol of this reimplementation is to separate the context switch mechanism of its implementation
(context switch implementation based ucontext, based native threads or java threads).
To do this, the code introduce a new concept : the context factory. This factory is responsible of
the construction of the context adapted to the desired context implementation. Normally, the context factory
to use is selected during the compilation process. But, for the java implementation of the context switch,
the simgrid library select dynamically the context factory to use (the java context factory to use). This
change also introduce three new concepts : the xbt_ucontext_t, the xbt_jcontext_t and the xbt_thread_context_t
which derived from the concept xbt_context_t. Each of them is specialized to respect an interface contract.
This contract is represented by function pointers such (start, stop, kill, schedule, yield...). For more details
on this function pointers see the source code file xbt_context.c.
The continuation gives the list of the modified, deleted and added files by this change.
Modified files:
src/msg/global.c get_pid is a function pointer
src/msg/private.h use xbt_context.h instead context.h
src/include/simix/simix.h java process management functions are not needed now
src/java/simgrid/msg/ApplicationHandler.java remove an useless printed message
src/java/simgrid/msg/msg.java simgrid for java and simgrid are now the same library so the name of the java library is also simgrid
add the call of the native function selectContextFactory() for the context switch based on the java threads
src/java/jmsg.c include the xbt_context_private.h which declare the context based java thread (jxbt_context.h doesn't exist any more)
declare an define a new function native_to_java_process which returns the java process associated with a msg process
define the native function java_simgrid_msg_Msg_selectContextFactory()
use the xbt_context_stop() function to signal the end of the java thread instead the function xbt_context_exit()
src/java/jmsg.h add the declaration of the java_simgrid_msg_Msg_selectContextFactory() function
src/java/jmsg_host.c this file is now inclued from the file src/xbt/xbt_jcontext.c which declare the log category for java, so the macro XBT_LOG_EXTERNAL_CATEGORY is useless
src/java/jmsg_parallel_task.c the same reason of the file src/java/jmsg_host.c
src/java/jmsg_process.c the same reason of the file src/java/jmsg_host.c and this file needs to include src/xbt/xbt_jprocess.h instead the file src/xbt/context_private.h to get
the definition of the java context
src/java/jmsg_process.h include xbt_context.h instead the context.h header
src/java/jxbt_utilities.c the same reason of the file src/java/jmsg_host.c
src/simix/private.h include xbt_context.h instead the header context.h
src/simix/smx_process.c modify the function SIMIX_jprocess_create() : this function doesn't use any more the simix java process management and the jprocess object is now passed as
the fourth parameter of the function xbt_context_new().
src/surf/network.c it's pointers to functions
src/surf/surfxml_parse.c just initialize the variable surf_file_to_parse to NULL
src/surf/workstation_KCCFLN05.c function pointers usage and ANSI C variable declarations
src/surf/workstation_ptask_L07.c function pointers usage and ANSI C variable declarations
src/surf/surf.c adapt the code to the specific path separator of Windows
src/xbt/xbt_main.c the function xbt_context_init() and xbt_context_exit() are now renamed xbt_context_mod_init() and xbt_context_mod_exit()
src/xbt/xbt_modinter.h declaration of xbt_context_mod_init() and xbt_context_mod_exit() functions
src/xbt/xbt_str.c avoid the warning thrown by the Visual C++ compiler when it meets a comparison between a signed and a unsigned integer
src/gras/rl_stubs.c use xbt_context_mod_init() and xbt_context_mod_exit() instead xbt_context_init() and xbt_context_exit()
src/makefile.am the java library build is now useless
src/makefile.in this is the consequence of the previous change (makefile.am)
Files to add:
src/xbt/xbt_context_private.h this header replace the file context_private.h
src/xbt/xbt_context.c this source file replace the file context.c
include/xbt/xbt_context.h this file replace the file context.h
src/xbt/xbt_context_factory.h this header declares the context factory structure used by xbt to build the adapted context
src/xbt/xbt_thread_context.h this header declares the structure used in the switch context process based on the native threads
src/xbt/xbt_thread_context.c this source file contains the implementation of the thread context
src/xbt/xbt_ucontext.h this header declares the structure used in the switch context process based on the ucontext
src/xbt/xbt_ucontext.c this source code file contains the implementation of the context based on the ucontext
src/xbt/xbt_jcontext.h this header contains the declaration of the structure used in the switch context process based on the java thread
src/xbt/xbt_jcontext.c this source code file contains the implementation of the context based on java thread
Files to delete:
src/xbt/context.c this file is replaced by the file src/xbt/xbt_context.c
src/include/xbt/context.h this file is replaced by the file include/xbt/xbt_context.h
src/xbt/context_private.h this file is replaced by the file src/xbt/xbt_context_private.h
src/java/jxbt_context.h this file is useless (reimplemented in xbt_context.h)
src/java/jxbt_context.c this file is useless (reimplemented in xbt_context.c)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@5040
48e7efb5-ca39-0410-a469-
dd3cf9ba447f
#include "xbt_modinter.h"
#include "xbt/sysdep.h"
-void xbt_context_init(void) {}
+void xbt_context_mod_init(void) {}
-void xbt_context_exit(void) {}
+void xbt_context_mod_exit(void) {}
void SIMIX_display_process_status(void);
-/* Helper functions for jMSG: manipulate the context data without breaking the module separation */
-void SIMIX_process_set_jprocess(smx_process_t process, void *jp);
-void* SIMIX_process_get_jprocess(smx_process_t process);
-void SIMIX_process_set_jenv(smx_process_t process, void *je);
-void* SIMIX_process_get_jenv(smx_process_t process);
-
SG_END_DECL()
#include "msg/msg.h"
#include "msg/private.h"
#include "simix/private.h"
-#include "java/jxbt_context.h"
+#include "xbt/xbt_context_private.h"
#include "jmsg_process.h"
#include "jmsg_host.h"
#include "jmsg_channel.h"
#include "jxbt_utilities.h"
-XBT_LOG_NEW_DEFAULT_CATEGORY(jmsg,"MSG for Java(TM)");
-
#include "jmsg.h"
static JavaVM * __java_vm = NULL;
+static jobject
+native_to_java_process(m_process_t process);
+
JavaVM *
get_java_VM(void) {
return __java_vm;
return env;
}
+static jobject
+native_to_java_process(m_process_t process)
+{
+ return ((xbt_jcontext_t)(process->simdata->s_process->simdata->context))->jprocess;
+}
+
/*
* The MSG process connected functions implementation.
/*data*/ (void*)process,
jprocess,env,
&process->simdata->s_process);
+
+
DEBUG1("context created (s_process=%p)",process->simdata->s_process);
}
/* delete the global reference */
- jprocess_delete_global_ref(SIMIX_process_get_jprocess(process->simdata->s_process),env);
+ jprocess_delete_global_ref(native_to_java_process(process),env);
/* kill the native process (this wrapper is call by the destructor of the java
* process instance)
return NULL;
}
- if(!SIMIX_process_get_jprocess(process->simdata->s_process)) {
+ if(!native_to_java_process(process)) {
jxbt_throw_native(env, xbt_strdup("SIMIX_process_get_jprocess() failed"));
return NULL;
}
- return (jobject)SIMIX_process_get_jprocess(process->simdata->s_process);
+ return (jobject)(native_to_java_process(process));
}
return NULL;
}
- jprocess = SIMIX_process_get_jprocess(process->simdata->s_process);
+ jprocess = native_to_java_process(process);
if(!jprocess)
jxbt_throw_native(env, xbt_strdup("SIMIX_process_get_jprocess() failed"));
}
process = MSG_task_get_sender(task);
- return SIMIX_process_get_jprocess(process->simdata->s_process);
+ return (jobject)native_to_java_process(process);
}
JNIEXPORT jobject JNICALL
process = MSG_task_get_sender(task);
- return SIMIX_process_get_jprocess(process->simdata->s_process);
+ return (jobject)native_to_java_process(process);
}
JNIEXPORT jobject JNICALL
return;
}
- jcontext_exit(process->simdata->s_process->simdata->context,0,get_current_thread_env());
+ xbt_context_stop(0);
}
JNIEXPORT void JNICALL
return jtable;
}
+
+JNIEXPORT void JNICALL
+Java_simgrid_msg_Msg_selectContextFactory(JNIEnv * env, jclass class,jstring jname)
+{
+ int rv;
+
+ /* get the C string from the java string*/
+ const char* name = (*env)->GetStringUTFChars(env, jname, 0);
+
+ rv = xbt_context_select_factory(name);
+
+ (*env)->ReleaseStringUTFChars(env, jname, name);
+
+ if(rv)
+ jxbt_throw_native(env, xbt_strdup("xbt_select_context_factory() failed"));
+}
JNIEXPORT void JNICALL
Java_simgrid_msg_Msg_processCreate(JNIEnv* env,jclass cls,jobject jprocess,jobject jhost);
+
+
/*
* Class simgrid_msg_Msg
* Method processSuspend
JNIEXPORT void JNICALL
Java_simgrid_msg_Msg_platformLoad(JNIEnv* env, jclass cls, jobject jplatform);
+
+JNIEXPORT void JNICALL
+Java_simgrid_msg_Msg_selectContextFactory(JNIEnv *, jclass, jstring);
+
#endif /* !MSG4JAVA_H */
#include "jmsg_host.h"
#include "jxbt_utilities.h"
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
-
jobject jhost_new_instance(JNIEnv* env) {
jclass cls = jxbt_get_class(env,"simgrid/msg/Host");
#include "jmsg_parallel_task.h"
#include "jxbt_utilities.h"
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
-
jobject
jparallel_task_ref(JNIEnv* env, jobject jparallel_task) {
jobject newref = (*env)->NewGlobalRef(env,jparallel_task);
#include "jmsg.h"
#include "jxbt_utilities.h"
-#ifndef JAVA_SIMGRID
-#define JAVA_SIMGRID
-#endif
-
-
-#include "xbt/context_private.h"
-
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
+#include "xbt/xbt_jcontext.h"
jobject
if(!id)
return;
- (*env)->CallVoidMethod(env,context->jprocess,id);
+ (*env)->CallVoidMethod(env,((xbt_jcontext_t)context)->jprocess,id);
}
if(!id)
return;
- (*env)->CallVoidMethod(env,context->jprocess,id);
+ (*env)->CallVoidMethod(env,((xbt_jcontext_t)context)->jprocess,id);
}
#include <jni.h>
#include "msg/msg.h"
-#include "xbt/context.h"
+#include "xbt/xbt_context.h"
/**
* This function returns a global reference to the java process instance
#include "xbt/str.h"
#include "jxbt_utilities.h"
-XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
-
/* *********** */
/* JNI GETTERS */
/* *********** */
public void createProcess(){
try {
- System.out.println("Create process " + function + " on the host " + hostName);
Class cls = Class.forName(this.function);
simgrid.msg.Process process = (simgrid.msg.Process)cls.newInstance();
process.name = process.getName(); //this.function;
process.id = simgrid.msg.Process.nextProcessId++;
Host host = Host.getByName(this.hostName);
Msg.processCreate(process,host);
-
Vector args = processFactory.args;
int size = args.size();
*/
static {
try {
- System.loadLibrary("simgrid4java");
+ System.loadLibrary("simgrid");
+ Msg.selectContextFactory("jcontext_factory");
+ } catch(NativeException e)
+ {
+ System.err.println(e.toString());
+ e.printStackTrace();
+ System.exit(1);
} catch(UnsatisfiedLinkError e){
- System.err.println("Cannot load simgrid4java library : ");
+ System.err.println("Cannot load simgrid library : ");
e.printStackTrace();
System.err.println("Please check your LD_LIBRARY_PATH, "+
"or copy the library to the current directory");
}
}
+ final static native
+ void selectContextFactory(String name) throws NativeException;
+
/******************************************************************
* The natively implemented methods connected to the MSG Process *
******************************************************************/
*/
void MSG_global_init(int *argc, char **argv)
{
- xbt_getpid = &MSG_process_self_PID;
+ xbt_getpid = MSG_process_self_PID;
if (!msg_global) {
SIMIX_global_init(argc, argv);
#include "xbt/dynar.h"
#include "xbt/swag.h"
#include "xbt/dict.h"
-#include "xbt/context.h"
+#include "xbt/xbt_context.h"
#include "xbt/config.h"
/**************** datatypes **********************************/
#include "xbt/fifo.h"
#include "xbt/swag.h"
#include "xbt/dict.h"
-#include "xbt/context.h"
+#include "xbt/xbt_context.h"
#include "xbt/config.h"
#include "xbt/function_types.h"
simdata->argc = 0;
simdata->argv = NULL;
- simdata->context = xbt_context_new(name,NULL, NULL, NULL,
+
+ simdata->context = xbt_context_new(name,NULL, NULL, jprocess,
simix_global->
cleanup_process_function, process,
/* argc/argv */ 0, NULL);
-
+
/* Process structure */
process->name = xbt_strdup(name);
process->simdata = simdata;
process->data = data;
- SIMIX_process_set_jprocess(process, jprocess);
- SIMIX_process_set_jenv(process, jenv);
xbt_swag_insert(process, host->simdata->process_list);
/* fix current_process, about which xbt_context_start mocks around */
self = simix_global->current_process;
+
xbt_context_start(process->simdata->context);
+
simix_global->current_process = self;
xbt_swag_insert(process, simix_global->process_list);
}
-/* Helper functions for jMSG: manipulate the context data without breaking the module separation */
-#include "xbt/context.h" /* to pass java objects from MSG to the context */
-
-void SIMIX_process_set_jprocess(smx_process_t process, void *jp)
-{
- xbt_context_set_jprocess(process->simdata->context, jp);
-}
-
-void *SIMIX_process_get_jprocess(smx_process_t process)
-{
- return xbt_context_get_jprocess(process->simdata->context);
-}
-
-void SIMIX_process_set_jenv(smx_process_t process, void *je)
-{
- xbt_context_set_jenv(process->simdata->context, je);
-}
-
-void *SIMIX_process_get_jenv(smx_process_t process)
-{
- return xbt_context_get_jenv(process->simdata->context);
-}
}
}
-static void add_loopback()
+static void add_loopback(void)
{
int i;
/* Adding loopback if needed */
}
}
-static void add_route()
+static void add_route(void)
{
xbt_ex_t e;
int nb_link = 0;
unsigned int cpt = 0;
int link_list_capacity = 0;
link_CM02_t *link_list = NULL;
+ char* link;
if (routing_table == NULL) create_routing_table();
src_id = atoi(xbt_dynar_get_as(keys, 0, char*));
dst_id = atoi(xbt_dynar_get_as(keys, 1, char*));
- char* link = NULL;
+ link = NULL;
xbt_dynar_foreach (links, cpt, link) {
TRY {
link_list[nb_link++] = xbt_dict_get(link_set, link);
static void define_callbacks(const char *file)
{
/* Figuring out the network links */
- surfxml_add_callback(STag_surfxml_host_cb_list, &count_hosts);
- surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
- surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
- surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
- surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
- surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
- surfxml_add_callback(STag_surfxml_platform_cb_list, &init_route_table);
- surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
- surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_loopback);
+ surfxml_add_callback(STag_surfxml_host_cb_list, count_hosts);
+ surfxml_add_callback(STag_surfxml_link_cb_list, parse_link_init);
+ surfxml_add_callback(STag_surfxml_prop_cb_list, parse_properties);
+ surfxml_add_callback(STag_surfxml_route_cb_list, parse_route_set_endpoints);
+ surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, parse_route_elem);
+ surfxml_add_callback(ETag_surfxml_route_cb_list, parse_route_set_route);
+ surfxml_add_callback(STag_surfxml_platform_cb_list, init_route_table);
+ surfxml_add_callback(ETag_surfxml_platform_cb_list, add_route);
+ surfxml_add_callback(ETag_surfxml_platform_cb_list, add_loopback);
}
static void *name_service(const char *name)
path_name_len = strlen(path) + strlen(name) + 1; /* plus '/' */
path_name = xbt_realloc(path_name, path_name_len + 1);
}
+ #ifdef WIN32
+ sprintf(path_name, "%s\\%s", path, name);
+ #else
sprintf(path_name, "%s/%s", path, name);
+ #endif
file = fopen(path_name, mode);
if (file)
return file;
static XBT_INLINE void surfxml_call_cb_functions(xbt_dynar_t);
YY_BUFFER_STATE surf_input_buffer;
-FILE *surf_file_to_parse;
+FILE *surf_file_to_parse = NULL;
void make_route_table(void)
{
void parse_platform_file(const char* file)
{
surf_parse_open(file);
- xbt_assert1((!surf_parse()), "Parse error in %s", file);
+ xbt_assert1((!(*surf_parse)()), "Parse error in %s", file);
surf_parse_close();
}
}
}
-static void add_loopback()
+static void add_loopback(void)
{
int i;
/* Adding loopback if needed */
}
}
-static void add_route()
+static void add_route(void)
{
xbt_ex_t e;
int nb_link = 0;
unsigned int cpt = 0;
int link_list_capacity = 0;
link_KCCFLN05_t *link_list = NULL;
+ char* link;
if (routing_table == NULL) create_routing_table();
impact_on_src_with_other_recv = atof(xbt_dynar_get_as(keys, 4, char*));
impact_on_dst_with_other_send = atof(xbt_dynar_get_as(keys, 5, char*));
- char* link = NULL;
+ link = NULL;
xbt_dynar_foreach (links, cpt, link) {
TRY {
link_list[nb_link++] = xbt_dict_get(link_set, link);
/* Adding callback functions */
surf_parse_reset_parser();
- surfxml_add_callback(STag_surfxml_host_cb_list, &parse_cpu_init);
- surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
- surfxml_add_callback(STag_surfxml_router_cb_list, &parse_routers);
- surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
- surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
- surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
- surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
- surfxml_add_callback(STag_surfxml_platform_cb_list, &init_route_table);
- surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
- surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_loopback);
+ surfxml_add_callback(STag_surfxml_host_cb_list, parse_cpu_init);
+ surfxml_add_callback(STag_surfxml_prop_cb_list, parse_properties);
+ surfxml_add_callback(STag_surfxml_router_cb_list, parse_routers);
+ surfxml_add_callback(STag_surfxml_link_cb_list, parse_link_init);
+ surfxml_add_callback(STag_surfxml_route_cb_list, parse_route_set_endpoints);
+ surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, parse_route_elem);
+ surfxml_add_callback(ETag_surfxml_route_cb_list, parse_route_set_route);
+ surfxml_add_callback(STag_surfxml_platform_cb_list, init_route_table);
+ surfxml_add_callback(ETag_surfxml_platform_cb_list, add_route);
+ surfxml_add_callback(ETag_surfxml_platform_cb_list, add_loopback);
}
/**************************************/
}
}
-static void add_route()
+static void add_route(void)
{
xbt_ex_t e;
int nb_link = 0;
unsigned int cpt = 0;
int link_list_capacity = 0;
link_L07_t *link_list = NULL;
+ char* link;
if (routing_table == NULL) create_routing_table();
link_list_capacity = xbt_dynar_length(links);
link_list = xbt_new(link_L07_t, link_list_capacity);
- char* link = NULL;
+ link = NULL;
xbt_dynar_foreach (links, cpt, link) {
TRY {
link_list[nb_link++] = xbt_dict_get(link_set, link);
{
/* Adding callback functions */
surf_parse_reset_parser();
- surfxml_add_callback(STag_surfxml_host_cb_list, &parse_cpu_init);
- surfxml_add_callback(STag_surfxml_prop_cb_list, &parse_properties);
- surfxml_add_callback(STag_surfxml_link_cb_list, &parse_link_init);
- surfxml_add_callback(STag_surfxml_route_cb_list, &parse_route_set_endpoints);
- surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, &parse_route_elem);
- surfxml_add_callback(ETag_surfxml_route_cb_list, &parse_route_set_route);
- surfxml_add_callback(STag_surfxml_platform_cb_list, &init_route_table);
- surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_route);
- surfxml_add_callback(ETag_surfxml_platform_cb_list, &add_loopback);
+ surfxml_add_callback(STag_surfxml_host_cb_list, parse_cpu_init);
+ surfxml_add_callback(STag_surfxml_prop_cb_list, parse_properties);
+ surfxml_add_callback(STag_surfxml_link_cb_list, parse_link_init);
+ surfxml_add_callback(STag_surfxml_route_cb_list, parse_route_set_endpoints);
+ surfxml_add_callback(ETag_surfxml_link_c_ctn_cb_list, parse_route_elem);
+ surfxml_add_callback(ETag_surfxml_route_cb_list, parse_route_set_route);
+ surfxml_add_callback(STag_surfxml_platform_cb_list, init_route_table);
+ surfxml_add_callback(ETag_surfxml_platform_cb_list, add_route);
+ surfxml_add_callback(ETag_surfxml_platform_cb_list, add_loopback);
}
/**************************************/
xbt_log_init(argc,argv);
xbt_os_thread_mod_init();
- xbt_context_init();
+ xbt_context_mod_init();
}
/** @brief Finalize the xbt mechanisms. */
if (xbt_initialized == 0) {
xbt_fifo_exit();
xbt_dict_exit();
- xbt_context_exit();
+ xbt_context_mod_exit();
xbt_os_thread_mod_exit();
xbt_log_exit();
}
res = xbt_malloc(len);
p=res;
xbt_dynar_foreach(dyn,cpt,cursor) {
- if (cpt<dyn_len-1)
+ if ((int)cpt<dyn_len-1)
p+=sprintf(p,"%s%s",cursor,sep);
else
p+=sprintf(p,"%s",cursor);
void xbt_fifo_exit(void);
void xbt_dict_exit(void);
-void xbt_context_init(void);
-void xbt_context_exit(void);
+void xbt_context_mod_init(void);
+void xbt_context_mod_exit(void);
void xbt_os_thread_mod_init(void);
void xbt_os_thread_mod_exit(void);