# Declare our package content #
###############################
set(JMSG_C_SRC
+ ${CMAKE_HOME_DIRECTORY}/src/smx_context_cojava.h
+ ${CMAKE_HOME_DIRECTORY}/src/smx_context_cojava.c
+ ${CMAKE_HOME_DIRECTORY}/src/jmsg_file.c
+ ${CMAKE_HOME_DIRECTORY}/src/jmsg_file.h
${CMAKE_HOME_DIRECTORY}/src/smx_context_java.h
${CMAKE_HOME_DIRECTORY}/src/smx_context_java.c
${CMAKE_HOME_DIRECTORY}/src/jxbt_utilities.c
${CMAKE_HOME_DIRECTORY}/src/jmsg_rngstream.h
)
+set(JTRACE_C_SRC
+ src/jtrace.c
+ src/jtrace.h
+)
+
set(JMSG_JAVA_SRC
${CMAKE_HOME_DIRECTORY}/org/simgrid/msg/Host.java
${CMAKE_HOME_DIRECTORY}/org/simgrid/msg/HostFailureException.java
- ${CMAKE_HOME_DIRECTORY}/org/simgrid/msg/HostNotFoundException.java
+ ${CMAKE_HOME_DIRECTORY}/org/simgrid/msg/HostNotFoundException.java
+ ${CMAKE_HOME_DIRECTORY}/org/simgrid/msg/File.java
${CMAKE_HOME_DIRECTORY}/org/simgrid/msg/JniException.java
${CMAKE_HOME_DIRECTORY}/org/simgrid/msg/Msg.java
${CMAKE_HOME_DIRECTORY}/org/simgrid/msg/MsgException.java
${CMAKE_HOME_DIRECTORY}/org/simgrid/msg/Comm.java
${CMAKE_HOME_DIRECTORY}/org/simgrid/msg/RngStream.java
)
+set(JTRACE_JAVA_SRC
+ org/simgrid/trace/Trace.java
+)
set(JAVA_EXAMPLES
${CMAKE_HOME_DIRECTORY}/examples/async/AsyncTest.java
${CMAKE_HOME_DIRECTORY}/examples/chord/FindSuccessorAnswerTask.java
${CMAKE_HOME_DIRECTORY}/examples/chord/FindSuccessorTask.java
${CMAKE_HOME_DIRECTORY}/examples/chord/GetPredecessorAnswerTask.java
- ${CMAKE_HOME_DIRECTORY}/examples/chord/GetPredecessorTask.java
${CMAKE_HOME_DIRECTORY}/examples/chord/NotifyTask.java
${CMAKE_HOME_DIRECTORY}/examples/commTime/FinalizeTask.java
${CMAKE_HOME_DIRECTORY}/examples/commTime/Master.java
${CMAKE_HOME_DIRECTORY}/examples/commTime/Slave.java
${CMAKE_HOME_DIRECTORY}/examples/commTime/CommTimeTest.java
+ ${CMAKE_HOME_DIRECTORY}/examples/io/IO.java
+ ${CMAKE_HOME_DIRECTORY}/examples/io/Node.java
${CMAKE_HOME_DIRECTORY}/examples/masterslave/FinalizeTask.java
${CMAKE_HOME_DIRECTORY}/examples/masterslave/Forwarder.java
${CMAKE_HOME_DIRECTORY}/examples/masterslave/Master.java
${CMAKE_HOME_DIRECTORY}/examples/pingPong/Sender.java
${CMAKE_HOME_DIRECTORY}/examples/pingPong/Receiver.java
${CMAKE_HOME_DIRECTORY}/examples/pingPong/PingPongTest.java
- ${CMAKE_HOME_DIRECTORY}/examples/priority/Priority.java
- ${CMAKE_HOME_DIRECTORY}/examples/priority/Test.java
${CMAKE_HOME_DIRECTORY}/examples/startKillTime/Master.java
${CMAKE_HOME_DIRECTORY}/examples/startKillTime/Slave.java
${CMAKE_HOME_DIRECTORY}/examples/startKillTime/StartKillTime.java
+ ${CMAKE_HOME_DIRECTORY}/examples/tracing/PingPongTask.java
${CMAKE_HOME_DIRECTORY}/examples/suspend/DreamMaster.java
${CMAKE_HOME_DIRECTORY}/examples/suspend/LazyGuy.java
${CMAKE_HOME_DIRECTORY}/examples/suspend/Suspend.java
+ ${CMAKE_HOME_DIRECTORY}/examples/tracing/Sender.java
+ ${CMAKE_HOME_DIRECTORY}/examples/tracing/Receiver.java
+ ${CMAKE_HOME_DIRECTORY}/examples/tracing/TracingTest.java
+
)
set(CMAKE_SRC
set(source_to_pack
${CMAKE_SRC}
${JMSG_C_SRC}
+ ${JTRACE_C_SRC}
${JMSG_JAVA_SRC}
+ ${JTRACE_JAVA_SRC}
${JAVA_EXAMPLES}
${XML_FILES}
${CMAKE_DOC_SRC}
string(REPLACE "org/" "classes/org/" JMSG_JAVA_SRC_CLASS "${JMSG_JAVA_SRC}")
string(REPLACE ".java" ".class" JMSG_JAVA_SRC_CLASS "${JMSG_JAVA_SRC_CLASS}")
+
+string(REPLACE "org/" "classes/org/" JTRACE_JAVA_SRC_CLASS "${JTRACE_JAVA_SRC}")
+string(REPLACE ".java" ".class" JTRACE_JAVA_SRC_CLASS "${JTRACE_JAVA_SRC_CLASS}")
+
string(REPLACE ".java" ".class" JAVA_EXAMPLES_CLASS "${JAVA_EXAMPLES}")
#########
set_target_properties(SG_java PROPERTIES LINK_FLAGS "-L${SIMGRID_LIB_PATH}")
endif(WIN32)
+# SG_java_tracing
+add_library(SG_java_tracing SHARED ${JTRACE_C_SRC})
+if(WIN32)
+ set_target_properties(SG_java_tracing PROPERTIES LINK_FLAGS "-Wl,--subsystem,windows,--kill-at ${SIMGRID_LIB}" PREFIX "")
+ find_path(PEXPORTS_PATH NAMES pexports.exe PATHS NO_DEFAULT_PATHS)
+ message(STATUS "pexports: ${PEXPORTS_PATH}")
+ if(PEXPORTS_PATH)
+ add_custom_command(TARGET SG_java_tracing POST_BUILD
+ COMMAND ${PEXPORTS_PATH}/pexports.exe ${CMAKE_BINARY_DIR}/SG_java_tracing.dll > ${CMAKE_BINARY_DIR}/SG_java_tracing.def)
+ endif(PEXPORTS_PATH)
+else(WIN32)
+ target_link_libraries(SG_java_tracing pcre pthread simgrid)
+ set_target_properties(SG_java_tracing PROPERTIES LINK_FLAGS "-L${SIMGRID_LIB_PATH}")
+endif(WIN32)
+
+
# java_classes
add_custom_command(
OUTPUT ${JMSG_JAVA_SRC_CLASS}
DEPENDS ${JMSG_JAVA_SRC}
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_HOME_DIRECTORY}/classes/"
COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/classes/
- -cp ${CMAKE_HOME_DIRECTORY}/classes/ ${JMSG_JAVA_SRC}
+ -cp ${CMAKE_HOME_DIRECTORY}/classes/ ${JMSG_JAVA_SRC}
COMMENT "Compiling java sources of core library..."
)
+
+add_custom_command(
+ OUTPUT ${JTRACE_JAVA_SRC_CLASS}
+ DEPENDS ${JTRACE_JAVA_SRC}
+ COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_HOME_DIRECTORY}/classes/"
+ COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/classes/
+ -cp ${CMAKE_HOME_DIRECTORY}/classes/ ${JAVA_FILES_TRACE}
+ COMMENT "Compiling java sources of core libraries..."
+)
+
add_custom_target(java_classes ALL
- DEPENDS ${JMSG_JAVA_SRC_CLASS}
+ DEPENDS ${JMSG_JAVA_SRC_CLASS} ${JTRACE_JAVA_SRC_CLASS}
)
# simgrid_jar
COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/bittorrent/*.java
COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/chord/*.java
COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/commTime/*.java
+ COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/io/*.java
COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/masterslave/*.java
COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/master_slave_bypass/*.java
COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/master_slave_kill/*.java
COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/migration/*.java
COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/mutualExclusion/centralized/*.java
+ COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/tracing/*.java
COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/pingPong/*.java
COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/priority/*.java
COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/startKillTime/*.java
# Declare dependencies #
########################
add_dependencies(simgrid_jar java_classes)
-add_dependencies(simgrid_java_examples simgrid_jar SG_java)
+add_dependencies(simgrid_java_examples simgrid_jar SG_java SG_java_tracing)
#####################
# Declare our tests #
ADD_TEST(priority ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/priority/priority.tesh)
ADD_TEST(startKillTime ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/startKillTime/startKillTime.tesh)
ADD_TEST(suspend ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/suspend/suspend.tesh)
+ADD_TEST(tracing ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/tracing/tracingPingPong.tesh)
#Don't forget to put new test in this list!!!
-set(test_list async bittorrent bypass chord commTime kill masterslave migration mutualExclusion pingPong priority startKillTime)
+set(test_list async bittorrent bypass chord commTime kill masterslave migration mutualExclusion pingPong priority startKillTime tracing)
##########################################
# Set the DYLD_LIBRARY_PATH for mac #
###########
install(TARGETS SG_java
DESTINATION $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/java/)
+
+install(TARGETS SG_java_tracing
+ DESTINATION $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/java/)
+
install(FILES ${CMAKE_HOME_DIRECTORY}/simgrid.jar
DESTINATION $ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/java/)
#########
# Dist #
#########
-
add_custom_target(dist-dir
COMMENT "Generating the distribution directory"
COMMAND test -e ${DIST_NAME}/ && chmod -R a+w ${DIST_NAME}/ || true
+SimGrid-java (3.8) unstable; urgency=low
+
+ * Introduce org.simgrid.trace.Trace (partial implementation of JAVA bindings
+ for the TRACE API).
+ Although all TRACE methods appear in the Trace class, please not that only
+ few of thems are really implemented at the JNI level (see ./src/jtrace.c
+ for further information).
+
SimGrid-java (3.7.1) stable; urgency=low
The "Java aint got to be bloated and slow" release
-
+
Major cleanups:
* Various internal cleanups and performance improvement
Simulations are expected to run up to twice faster or so
--- /dev/null
+/*
+ * 2012. The SimGrid Team. All rights reserved.
+ *
+ * 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.
+ */
+package io;
+
+import org.simgrid.msg.Host;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.MsgException;
+/**
+ * This example demonstrates of how to use the other
+ * kind of resources, such as disk or GPU. These resources are quite
+ * experimental for now, but here we go anyway.
+ */
+public class IO {
+ public static void main(String[] args) throws MsgException {
+ Msg.init(args);
+ if(args.length < 1) {
+ Msg.info("Usage : IO platform_file ");
+ Msg.info("example : IO platform.xml ");
+ System.exit(1);
+ }
+ Msg.createEnvironment(args[0]);
+
+ Host[] hosts = Host.all();
+
+ Msg.info("Number of hosts:" + hosts.length);
+ for (int i = 0; i < hosts.length && i < 4; i++) {
+ new io.Node(hosts[i],i).start();
+ }
+
+ Msg.run();
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * 2012. The SimGrid Team. All rights reserved.
+ *
+ * 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.
+ */
+package io;
+
+import org.simgrid.msg.File;
+import org.simgrid.msg.Host;
+import org.simgrid.msg.HostNotFoundException;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.MsgException;
+import org.simgrid.msg.Process;
+
+public class Node extends Process {
+ private static String FILENAME1 = "/home/user/Install/simgrid/doc/simgrid/examples/platforms/g5k.xml";
+ private static String FILENAME2 = "/home/user/Install/simgrid/doc/simgrid/examples/platforms/One_cluster_no_backbone.xml";
+ private static String FILENAME3 = "/home/user/Install/simgrid/doc/simgrid/examples/platforms/g5k_cabinets.xml";
+ private static String FILENAME4 = "/home/user/Install/simgrid/doc/simgrid/examples/platforms/nancy.xml";
+
+ protected int number;
+
+ public Node(Host host, int number) throws HostNotFoundException {
+ super(host, Integer.toString(number), null);
+ this.number = number;
+ }
+ public void main(String[] args) throws MsgException {
+ String mount = "C:";
+ String filename;
+ switch (number) {
+ case 0:
+ filename = FILENAME1;
+ break;
+ case 1:
+ filename = FILENAME2;
+ break;
+ case 2:
+ filename = FILENAME3;
+ break;
+ case 3:
+ filename = FILENAME4;
+ break;
+ default:
+ filename = FILENAME1;
+ }
+ Msg.info("Open file " + filename);
+ File file = new File(mount,filename, "rw");
+
+ long read = file.read(mount,10000000,1);
+ Msg.info("Having read " + read + " on " + filename);
+
+ long write = file.read(mount,100000,1);
+ Msg.info("Having write " + write + " on " + filename);
+
+ read = file.read(mount,10000000,1);
+ Msg.info("Having read " + read + " on " + filename);
+ }
+}
\ No newline at end of file
--- /dev/null
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
+
+<platform version="3">
+
+ <AS id="AS0" routing="Full">
+
+ <storage_type id="samsung" model="RAID5" content="content/storage_content.txt" size="500">
+ <prop id="Bwrite" value="30000000" /> <!-- 30Mo/s -->
+ <prop id="Bread" value="100000000" /> <!-- 100Mo/s -->
+ <prop id="Bconnection" value="150000000" /> <!-- 150Mo/s -->
+ </storage_type>
+
+ <storage_type id="crucial" model="SSD" content="content/storage_content.txt" size="500">
+ <prop id="Bwrite" value="30000000" />
+ <prop id="Bread" value="100000000" />
+ <prop id="Bconnection" value="150000000" />
+ </storage_type>
+
+ <storage_type id="wdigital" model="RAID0" content="content/storage_content.txt" size="500">
+ <prop id="Bwrite" value="30000000" />
+ <prop id="Bread" value="100000000" />
+ <prop id="Bconnection" value="150000000" />
+ </storage_type>
+
+ <storage id="Disk1" typeId="crucial"/>
+ <storage id="Disk2" typeId="samsung"/>
+ <storage id="Disk3" typeId="wdigital"/>
+ <storage id="Disk4" typeId="wdigital"/>
+
+ <host id="bob" power="1000000000">
+ <mount id="Disk1" name="C:"/>
+ </host>
+
+ <host id="alice" power="1000000000">
+ <mount id="Disk2" name="C:"/>
+ </host>
+
+ <host id="carl" power="1000000000">
+ <mount id="Disk3" name="C:"/>
+ </host>
+
+ <host id="denise" power="1000000000">
+ <mount id="Disk4" name="C:"/>
+ </host>
+
+ <link id="link1" bandwidth="125000000" latency="5E-5" />
+ <link id="link2" bandwidth="125000000" latency="5E-5" />
+ <link id="link3" bandwidth="125000000" latency="5E-5" />
+
+ <route src="bob" dst="alice" symmetrical="YES">
+ <link_ctn id="link1" />
+ <link_ctn id="link2" />
+ <link_ctn id="link3" />
+ </route>
+
+ </AS>
+</platform>
--- /dev/null
+/*
+ * Copyright 2006,2007,2010. The SimGrid Team. All rights reserved.
+ *
+ * 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.
+ */
+
+package tracing;
+import org.simgrid.msg.NativeException;
+import org.simgrid.msg.Task;
+
+public class PingPongTask extends Task {
+
+ private double timeVal;
+
+ public PingPongTask() throws NativeException {
+ this.timeVal = 0;
+ }
+
+ public PingPongTask(String name, double computeDuration, double messageSize) throws NativeException {
+ super(name,computeDuration,messageSize);
+ }
+
+ public void setTime(double timeVal){
+ this.timeVal = timeVal;
+ }
+
+ public double getTime() {
+ return this.timeVal;
+ }
+}
+
--- /dev/null
+This is a stupid ping/pong example. The processes exchange a simple
+task and time them.
\ No newline at end of file
--- /dev/null
+/*
+ * $Id$
+ *
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier
+ * Copyright 2012 The SimGrid Team. All rights reserved.
+ * All rights reserved.
+ *
+ * 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.
+ */
+package tracing;
+import org.simgrid.msg.Host;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.MsgException;
+import org.simgrid.msg.Task;
+import org.simgrid.msg.Process;
+import org.simgrid.trace.Trace;
+
+public class Receiver extends Process {
+
+ private final double commSizeLat = 1;
+ private final double commSizeBw = 100000000;
+
+ public Receiver(Host host, String name, String[]args) {
+ super(host,name,args);
+ }
+
+ public void main(String[] args) throws MsgException {
+
+ Msg.info("hello!");
+ Trace.hostPushState (host.getName(), "PM_STATE", "waitingPing");
+ double communicationTime=0;
+
+ double time = Msg.getClock();
+
+ /* Wait for the ping */
+ Msg.info("try to get a task");
+
+ PingPongTask ping = (PingPongTask)Task.receive(getHost().getName());
+ double timeGot = Msg.getClock();
+ double timeSent = ping.getTime();
+
+ Msg.info("Got at time "+ timeGot);
+ Msg.info("Was sent at time "+timeSent);
+ time=timeSent;
+
+ communicationTime=timeGot - time;
+ Msg.info("Communication time : " + communicationTime);
+
+ Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----");
+
+ /* Send the pong */
+ Trace.hostPushState (host.getName(), "PM_STATE", "sendingPong");
+ double computeDuration = 0;
+ PingPongTask pong = new PingPongTask("no name",computeDuration,commSizeLat);
+ pong.setTime(time);
+ pong.send(ping.getSource().getName());
+
+ /* Pop the two states */
+ Trace.hostPopState (host.getName(), "PM_STATE");
+ Trace.hostPopState (host.getName(), "PM_STATE");
+
+ Msg.info("goodbye!");
+ }
+}
--- /dev/null
+/*
+ * Sender of basic ping/pong example
+ *
+ * Copyright 2006,2007,2010, 2012 The SimGrid Team. All rights reserved.
+ *
+ * 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.
+ */
+package tracing;
+import org.simgrid.msg.Host;
+import org.simgrid.msg.HostNotFoundException;
+import org.simgrid.msg.Msg;
+import org.simgrid.msg.Task;
+import org.simgrid.msg.MsgException;
+import org.simgrid.msg.Process;
+import org.simgrid.trace.Trace;
+
+public class Sender extends Process {
+
+ private final double commSizeLat = 1;
+ private final double commSizeBw = 100000000;
+
+ public Sender(Host host, String name, String[] args) {
+ super(host,name,args);
+ }
+
+ public void main(String[] args) throws MsgException {
+ Msg.info("hello !");
+ Trace.hostPushState (host.getName(), "PM_STATE", "sendingPing");
+
+ int hostCount = args.length;
+ Msg.info("host count: " + hostCount);
+ String mailboxes[] = new String[hostCount];
+ double time;
+ double computeDuration = 0;
+ PingPongTask ping, pong;
+
+ for(int pos = 0; pos < args.length ; pos++) {
+ try {
+ mailboxes[pos] = Host.getByName(args[pos]).getName();
+ } catch (HostNotFoundException e) {
+ Msg.info("Invalid deployment file: " + e.toString());
+ System.exit(1);
+ }
+ }
+
+ for (int pos = 0; pos < hostCount; pos++) {
+ time = Msg.getClock();
+ Msg.info("sender time: " + time);
+ ping = new PingPongTask("no name",computeDuration,commSizeLat);
+ ping.setTime(time);
+ ping.send(mailboxes[pos]);
+
+ Trace.hostPushState (host.getName(), "PM_STATE", "waitingPong");
+ pong = (PingPongTask)Task.receive(getHost().getName());
+ double timeGot = Msg.getClock();
+ double timeSent = ping.getTime();
+ double communicationTime=0;
+
+ Msg.info("Got at time "+ timeGot);
+ Msg.info("Was sent at time "+timeSent);
+ time=timeSent;
+
+ communicationTime=timeGot - time;
+ Msg.info("Communication time : " + communicationTime);
+
+ Msg.info(" --- bw "+ commSizeBw/communicationTime + " ----");
+
+ /* Pop the last state (going back to sending ping) */
+ Trace.hostPopState (host.getName(), "PM_STATE");
+
+ }
+ /* Pop the sendingPong state */
+ Trace.hostPopState (host.getName(), "PM_STATE");
+ Msg.info("goodbye!");
+ }
+}
--- /dev/null
+/*
+ * $Id$
+ *
+ * Copyright 2006,2007 Martin Quinson, Malek Cherier
+ * Copyright 2012 The SimGrid team
+ * All rights reserved.
+ *
+ * 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.
+ */
+package tracing;
+import org.simgrid.msg.Msg;
+import org.simgrid.trace.Trace;
+import org.simgrid.msg.NativeException;
+
+public class TracingTest {
+
+ /* This only contains the launcher. If you do nothing more than than you can run
+ * java simgrid.msg.Msg
+ * which also contains such a launcher
+ */
+
+ public static void main(String[] args) throws NativeException {
+ /* initialize the MSG simulation. Must be done before anything else (even logging). */
+ Msg.init(args);
+ if(args.length < 2) {
+ Msg.info("Usage : PingPong platform_file deployment_file");
+ Msg.info("example : PingPong ping_pong_platform.xml ping_pong_deployment.xml");
+ System.exit(1);
+ }
+
+ /* construct the platform and deploy the application */
+ Msg.createEnvironment(args[0]);
+ Msg.deployApplication(args[1]);
+
+ /* Initialize some state for the hosts */
+ Trace.hostStateDeclare ("PM_STATE");
+ Trace.hostStateDeclareValue ("PM_STATE", "waitingPing", "0 0 1");
+ Trace.hostStateDeclareValue ("PM_STATE", "sendingPong", "0 1 0");
+ Trace.hostStateDeclareValue ("PM_STATE", "sendingPing", "0 1 1");
+ Trace.hostStateDeclareValue ("PM_STATE", "waitingPong", "1 0 0");
+
+ /* execute the simulation. */
+ Msg.run();
+ Msg.clean();
+ }
+}
--- /dev/null
+#! ./tesh
+
+! output sort
+
+$ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar tracing/TracingTest ${srcdir:=.}/examples/platform.xml ${srcdir:=.}/examples/tracing/tracingPingPongDeployment.xml --cfg=tracing:1 --cfg=tracing/filename:simulation.trace --cfg=tracing/platform:1
+> [0.000000] [jmsg/INFO] Ready to run MSG_MAIN
+> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing' to '1'
+> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/filename' to 'simulation.trace'
+> [0.000000] [xbt_cfg/INFO] Configuration change: Set 'tracing/platform' to '1'
+> [4.474433] [jmsg/INFO] Done running MSG_MAIN
+> [4.474433] [jmsg/INFO] MSG_main finished
+> [4.474433] [jmsg/INFO] Clean java world
+> [4.474433] [jmsg/INFO] Clean native world
+> [Boivin:tracing.Receiver:(2) 0.000000] [jmsg/INFO] hello!
+> [Boivin:tracing.Receiver:(2) 0.000000] [jmsg/INFO] try to get a task
+> [Boivin:tracing.Receiver:(2) 1.048890] [jmsg/INFO] Got at time 1.0488895059341703
+> [Boivin:tracing.Receiver:(2) 1.048890] [jmsg/INFO] Was sent at time 0.0
+> [Boivin:tracing.Receiver:(2) 1.048890] [jmsg/INFO] Communication time : 1.0488895059341703
+> [Boivin:tracing.Receiver:(2) 1.048890] [jmsg/INFO] --- bw 9.533892696441577E7 ----
+> [Boivin:tracing.Receiver:(2) 2.097779] [jmsg/INFO] goodbye!
+> [Jacquelin:tracing.Sender:(1) 0.000000] [jmsg/INFO] hello !
+> [Jacquelin:tracing.Sender:(1) 0.000000] [jmsg/INFO] host count: 2
+> [Jacquelin:tracing.Sender:(1) 0.000000] [jmsg/INFO] sender time: 0.0
+> [Jacquelin:tracing.Sender:(1) 2.097779] [jmsg/INFO] Got at time 2.09777901186834
+> [Jacquelin:tracing.Sender:(1) 2.097779] [jmsg/INFO] Was sent at time 0.0
+> [Jacquelin:tracing.Sender:(1) 2.097779] [jmsg/INFO] Communication time : 2.09777901186834
+> [Jacquelin:tracing.Sender:(1) 2.097779] [jmsg/INFO] --- bw 4.7669463482207894E7 ----
+> [Jacquelin:tracing.Sender:(1) 2.097779] [jmsg/INFO] sender time: 2.09777901186834
+> [Jacquelin:tracing.Sender:(1) 4.474433] [jmsg/INFO] Got at time 4.47443270471118
+> [Jacquelin:tracing.Sender:(1) 4.474433] [jmsg/INFO] Was sent at time 2.09777901186834
+> [Jacquelin:tracing.Sender:(1) 4.474433] [jmsg/INFO] Communication time : 2.37665369284284
+> [Jacquelin:tracing.Sender:(1) 4.474433] [jmsg/INFO] --- bw 4.207596601101137E7 ----
+> [Jacquelin:tracing.Sender:(1) 4.474433] [jmsg/INFO] goodbye!
+> [Marcel:tracing.Receiver:(3) 0.000000] [jmsg/INFO] hello!
+> [Marcel:tracing.Receiver:(3) 0.000000] [jmsg/INFO] try to get a task
+> [Marcel:tracing.Receiver:(3) 3.057947] [jmsg/INFO] Got at time 3.05794733778171
+> [Marcel:tracing.Receiver:(3) 3.057947] [jmsg/INFO] Was sent at time 2.09777901186834
+> [Marcel:tracing.Receiver:(3) 3.057947] [jmsg/INFO] Communication time : 0.96016832591337
+> [Marcel:tracing.Receiver:(3) 3.057947] [jmsg/INFO] --- bw 1.0414840533806817E8 ----
+> [Marcel:tracing.Receiver:(3) 4.474433] [jmsg/INFO] goodbye!
--- /dev/null
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
+<platform version="3">
+ <process host="Jacquelin" function="tracing.Sender">
+ <argument value="Boivin"/>
+ <argument value="Marcel"/>
+ </process>
+<process host="Boivin" function="tracing.Receiver"/>
+<process host="Marcel" function="tracing.Receiver"/>
+</platform>
--- /dev/null
+package org.simgrid.msg;
+/**
+* Copyright 2012 The SimGrid team. All right reserved.
+*
+* 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.
+*
+*/
+
+public class File {
+ protected String storage;
+ /**
+ * Represents the bind between the java comm and the
+ * native C comm. You must never access it, since it is
+ * automatically set.
+ */
+ public long bind = 0;
+ /**
+ * Constructor, opens the file.
+ * @param storage is the name where you can find the stream
+ * @param path is the file location on the storage
+ * @param mode points to a string beginning with one of the following sequences (Additional characters may follow these sequences.): r Open text file for reading. The stream is positioned at the beginning of the file. r+ Open for reading and writing. The stream is positioned at the beginning of the file. w Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file. w+ Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file. a Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned at the end of the file. a+ Open for reading and appending (writing at end of file). The file is created if it does not exist. The initial file position for reading is at the beginning of the file, but output is always appended to the end of the file.
+ */
+ public File(String storage, String path, String mode) {
+ this.storage = storage;
+ open(storage, path, mode);
+ }
+ protected void finalize() {
+ close(storage);
+ }
+ /**
+ * Opens the file whose name is the string pointed to by path.
+ * @param storage is the name where you can find the stream
+ * @param path is the file location on the storage
+ * @param mode points to a string beginning with one of the following sequences (Additional characters may follow these sequences.): r Open text file for reading. The stream is positioned at the beginning of the file. r+ Open for reading and writing. The stream is positioned at the beginning of the file. w Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file. w+ Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file. a Open for appending (writing at end of file). The file is created if it does not exist. The stream is positioned at the end of the file. a+ Open for reading and appending (writing at end of file). The file is created if it does not exist. The initial file position for reading is at the beginning of the file, but output is always appended to the end of the file.
+ */
+ protected native void open(String storage, String path, String mode);
+ /**
+ * Read elements of a file.
+ * @param storage is the name where you can find the stream
+ * @param size of each element
+ * @param nMemb is the number of elements of data to write
+ */
+ public native long read(String storage, long size, long nMemb);
+ /**
+ * Write elements into a file.
+ * @param storage is the name where you can find the stream
+ * @param size of each element
+ * @param nMemb is the number of elements of data to write
+ */
+ public native long write(String storage, long size, long nMemb);
+ /**
+ * Close the file.
+ * @param storage is the name where you can find the stream
+ */
+ public native void close(String storage);
+
+ /**
+ * Class initializer, to initialize various JNI stuff
+ */
+ public static native void nativeInit();
+ static {
+ nativeInit();
+ }
+}
\ No newline at end of file
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);
--- /dev/null
+package org.simgrid.trace;
+
+/*
+ * JNI interface to C code for the TRACES part of SimGrid.
+ *
+ * Copyright 2006,2007,2010,2011, 2012 The SimGrid Team.
+ * All right reserved.
+ *
+ * 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.
+ */
+
+public final class Trace {
+ /* Statically load the library which contains all native functions used in here */
+ static {
+ try {
+ System.loadLibrary("SG_java_tracing");
+ } catch(UnsatisfiedLinkError e) {
+ System.err.println("Cannot load the bindings to the simgrid library: ");
+ e.printStackTrace();
+ System.err.println(
+ "Please check your LD_LIBRARY_PATH, or copy the simgrid and SG_java_tracing libraries to the current directory");
+ System.exit(1);
+ }
+ }
+
+ // TODO complete the binding of the tracing API
+
+ /**
+ * Declare a new user variable associated to hosts.
+ *
+ * @param variable
+ */
+ public final static native void hostVariableDeclare (String variable);
+
+ /**
+ * Declare a new user variable associated to hosts with a color.
+ *
+ * @param variable
+ * @param color
+ */
+ public final static native void hostVariableDeclareWithColor (String variable, String color);
+
+ /**
+ * Set the value of a variable of a host.
+ *
+ * @param host
+ * @param variable
+ * @param value
+ */
+ public final static native void hostVariableSet (String host, String variable, double value);
+
+ /**
+ * Add a value to a variable of a host.
+ *
+ * @param host
+ * @param variable
+ * @param value
+ */
+ public final static native void hostVariableAdd (String host, String variable, double value);
+
+ /**
+ * Subtract a value from a variable of a host.
+ *
+ * @param host
+ * @param variable
+ * @param value
+ */
+ public final static native void hostVariableSub (String host, String variable, double value);
+
+ /**
+ * Set the value of a variable of a host at a given timestamp.
+ *
+ * @param time
+ * @param host
+ * @param variable
+ * @param value
+ */
+ public final static native void hostVariableSetWithTime (double time, String host, String variable, double value);
+
+ /**
+ * Add a value to a variable of a host at a given timestamp.
+ *
+ * @param time
+ * @param host
+ * @param variable
+ * @param value
+ */
+ public final static native void hostVariableAddWithTime (double time, String host, String variable, double value);
+
+ /**
+ * Subtract a value from a variable of a host at a given timestamp.
+ *
+ * @param time
+ * @param host
+ * @param variable
+ * @param value
+ */
+ public final static native void hostVariableSubWithTime (double time, String host, String variable, double value);
+
+ /**
+ * Get declared user host variables.
+ *
+ */
+ public final static native String[] getHostVariablesName ();
+
+ /**
+ * Declare a new user variable associated to links.
+ *
+ * @param variable
+ */
+ public final static native void linkVariableDeclare (String variable);
+
+ /**
+ * Declare a new user variable associated to links with a color.
+ * @param variable
+ * @param color
+ */
+ public final static native void linkVariableDeclareWithColor (String variable, String color);
+
+ /**
+ * Set the value of a variable of a link.
+ *
+ * @param link
+ * @param variable
+ * @param value
+ */
+ public final static native void linkVariableSet (String link, String variable, double value);
+
+ /**
+ * Add a value to a variable of a link.
+ *
+ * @param link
+ * @param variable
+ * @param value
+ */
+ public final static native void linkVariableAdd (String link, String variable, double value);
+
+ /**
+ * Subtract a value from a variable of a link.
+ *
+ * @param link
+ * @param variable
+ * @param value
+ */
+ public final static native void linkVariableSub (String link, String variable, double value);
+
+ /**
+ * Set the value of a variable of a link at a given timestamp.
+ *
+ * @param time
+ * @param link
+ * @param variable
+ * @param value
+ */
+ public final static native void linkVariableSetWithTime (double time, String link, String variable, double value);
+
+ /**
+ * Add a value to a variable of a link at a given timestamp.
+ *
+ * @param time
+ * @param link
+ * @param variable
+ * @param value
+ */
+ public final static native void linkVariableAddWithTime (double time, String link, String variable, double value);
+
+
+ /**
+ * Subtract a value from a variable of a link at a given timestamp.
+ *
+ * @param time
+ * @param link
+ * @param variable
+ * @param value
+ */
+ public final static native void linkVariableSubWithTime (double time, String link, String variable, double value);
+
+ /**
+ * Set the value of the variable present in the links connecting source and destination.
+ *
+ * @param src
+ * @param dst
+ * @param variable
+ * @param value
+ */
+ public final static native void linkSrcDstVariableSet (String src, String dst, String variable, double value);
+
+ /**
+ * Add a value to the variable present in the links connecting source and destination.
+ *
+ * @param src
+ * @param dst
+ * @param variable
+ * @param value
+ */
+ public final static native void linkSrcDstVariableAdd (String src, String dst, String variable, double value);
+
+ /**
+ * Subtract a value from the variable present in the links connecting source and destination.
+ *
+ * @param src
+ * @param dst
+ * @param variable
+ * @param value
+ */
+ public final static native void linkSrcDstVariableSub (String src, String dst, String variable, double value);
+
+ /**
+ * Set the value of the variable present in the links connecting source and destination at a given timestamp.
+ *
+ * @param time
+ * @param src
+ * @param dst
+ * @param variable
+ * @param value
+ */
+ public final static native void linkSrcDstVariableSetWithTime (double time, String src, String dst, String variable, double value);
+
+ /**
+ * Add a value to the variable present in the links connecting source and destination at a given timestamp.
+ *
+ * @param time
+ * @param src
+ * @param dst
+ * @param variable
+ * @param value
+ */
+ public final static native void linkSrcdstVariableAddWithTime (double time, String src, String dst, String variable, double value);
+
+ /**
+ * Subtract a value from the variable present in the links connecting source and destination at a given timestamp.
+ *
+ * @param time
+ * @param src
+ * @param dst
+ * @param variable
+ * @param value
+ */
+ public final static native void linkSrcDstVariableSubWithTime (double time, String src, String dst, String variable, double value);
+
+ /**
+ * Get declared user link variables.
+ */
+ public final static native String[] getLinkVariablesName ();
+
+
+ /* **** ******** WARNINGS ************** ***** */
+ /* Only the following routines have been */
+ /* JNI implemented - Adrien May, 22nd */
+ /* **** ******************************** ***** */
+
+ /**
+ * Declare a user state that will be associated to hosts.
+ * A user host state can be used to trace application states.
+ *
+ * @param name The name of the new state to be declared.
+ */
+ public final static native void hostStateDeclare(String name);
+
+ /**
+ * Declare a new value for a user state associated to hosts.
+ * The color needs to be a string with three numbers separated by spaces in the range [0,1].
+ * A light-gray color can be specified using "0.7 0.7 0.7" as color.
+ *
+ * @param state The name of the new state to be declared.
+ * @param value The name of the value
+ * @param color The color of the value
+ */
+ public final static native void hostStateDeclareValue (String state, String value, String color);
+
+ /**
+ * Set the user state to the given value.
+ * (the queue is totally flushed and reinitialized with the given state).
+ *
+ * @param host The name of the host to be considered.
+ * @param state The name of the state previously declared.
+ * @param value The new value of the state.
+ */
+ public final static native void hostSetState (String host, String state, String value);
+
+ /**
+ * Push a new value for a state of a given host.
+ *
+ * @param host The name of the host to be considered.
+ * @param state The name of the state previously declared.
+ * @param value The value to be pushed.
+ */
+ public final static native void hostPushState (String host, String state, String value);
+
+ /**
+ * Pop the last value of a state of a given host.
+ *
+ * @param host The name of the host to be considered.
+ * @param state The name of the state to be popped.
+ */
+ public final static native void hostPopState (String host, String state);
+
+
+}
#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;
--- /dev/null
+/* Functions related to the java file API. */
+/* Copyright (c) 2012. The SimGrid Team.
+ * All rights reserved. */
+
+/* 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 "jmsg_file.h"
+#include "jxbt_utilities.h"
+void jfile_bind(JNIEnv *env, jobject jfile, msg_file_t stream) {
+ (*env)->SetLongField(env, jfile, jfile_field_bind, (jlong) (long) (stream));
+}
+
+msg_file_t jfile_get_native(JNIEnv *env, jobject jfile) {
+ msg_file_t file = (msg_file_t)(*env)->GetLongField(env, jfile, jfile_field_bind);
+ return file;
+}
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_File_nativeInit(JNIEnv *env, jclass cls) {
+ jclass class_File = (*env)->FindClass(env, "org/simgrid/msg/File");
+ jfile_field_bind = jxbt_get_jfield(env , class_File, "bind", "J");
+ xbt_assert((jfile_field_bind != NULL), "Can't find \"bind\" field in File class.");
+}
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_File_open(JNIEnv *env, jobject jfile, jobject jstorage, jobject jpath, jobject jmode) {
+
+ const char *storage = (*env)->GetStringUTFChars(env, jstorage, 0);
+ const char *path = (*env)->GetStringUTFChars(env, jpath, 0);
+ const char *mode = (*env)->GetStringUTFChars(env, jmode, 0);
+
+ msg_file_t file = MSG_file_open(storage, path, mode);
+
+ jfile_bind(env, jfile, file);
+
+ (*env)->ReleaseStringUTFChars(env, jstorage, storage);
+ (*env)->ReleaseStringUTFChars(env, jpath, path);
+ (*env)->ReleaseStringUTFChars(env, jmode, mode);
+}
+JNIEXPORT jlong JNICALL
+Java_org_simgrid_msg_File_read(JNIEnv *env, jobject jfile, jobject jstorage, jlong jsize, jlong jnmemb) {
+ msg_file_t file = jfile_get_native(env, jfile);
+
+ const char *storage = (*env)->GetStringUTFChars(env, jstorage, 0);
+
+ size_t n = MSG_file_read(storage, NULL,(size_t)jsize, (size_t)jnmemb, file);
+
+ (*env)->ReleaseStringUTFChars(env, jstorage, storage);
+
+ return (jlong)n;
+}
+
+JNIEXPORT jlong JNICALL
+Java_org_simgrid_msg_File_write(JNIEnv *env, jobject jfile, jobject jstorage, jlong jsize, jlong jnmemb) {
+ msg_file_t file = jfile_get_native(env, jfile);
+
+ const char *storage = (*env)->GetStringUTFChars(env, jstorage, 0);
+
+ size_t n = MSG_file_write(storage, NULL, (size_t)jsize, (size_t)jnmemb, file);
+
+ (*env)->ReleaseStringUTFChars(env, jstorage, storage);
+
+ return (jlong)n;
+}
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_File_close(JNIEnv *env, jobject jfile, jobject jstorage) {
+ msg_file_t file = jfile_get_native(env, jfile);
+
+ const char *storage = (*env)->GetStringUTFChars(env, jstorage, 0);
+
+ MSG_file_close(storage, file);
+ jfile_bind(env, jfile, NULL);
+
+ (*env)->ReleaseStringUTFChars(env, jstorage, storage);
+
+}
+
--- /dev/null
+/* Functions related to the java file API. */
+/* Copyright (c) 2012. The SimGrid Team.
+ * All rights reserved. */
+
+/* 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. */
+
+#ifndef MSG_JFILE_H
+#define MSG_JFILE_H
+#include <jni.h>
+#include "msg/msg.h"
+
+jfieldID jfile_field_bind;
+
+void jfile_bind(JNIEnv *env, jobject jfile, msg_file_t stream);
+msg_file_t jfile_get_native(JNIEnv *env, jobject jfile);
+/**
+ * Class org_simgrid_msg_File
+ * Method nativeInit
+ * Signature ()V
+ */
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_File_nativeInit(JNIEnv*, jclass);
+/**
+ * Class org_simgrid_msg_File
+ * Method open
+ * Signature (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_File_open(JNIEnv*, jobject, jobject, jobject, jobject);
+/**
+ * Class org_simgrid_msg_File
+ * Method read
+ */
+JNIEXPORT jlong JNICALL
+Java_org_simgrid_msg_File_read(JNIEnv*, jobject, jobject, jlong, jlong);
+/**
+ * Class org_simgrid_msg_File
+ * Method write
+ */
+JNIEXPORT jlong JNICALL
+Java_org_simgrid_msg_File_write(JNIEnv*, jobject, jobject, jlong, jlong);
+/**
+ * Class org_simgrid_msg_File
+ * Method close
+ */
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_File_close(JNIEnv*, jobject, jobject);
+
+#endif
#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;
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);
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));
--- /dev/null
+/* Java Wrappers to the TRACE API. */
+
+/* Copyright (c) 2012 The SimGrid Team.
+ * All rights reserved. */
+
+/* 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. */
+
+
+// Please note, this file strongly relies on the jmsg.c,
+// It will be great that a JNI expert gives a look to validate it - Adrien ;)
+
+#include "jtrace.h"
+#include <instr/instr.h>
+
+/* Shut up some errors in eclipse online compiler. I wish such a pimple wouldn't be needed */
+#ifndef JNIEXPORT
+#define JNIEXPORT
+#endif
+#ifndef JNICALL
+#define JNICALL
+#endif
+/* end of eclipse-mandated pimple */
+
+// Define a new category
+XBT_LOG_NEW_DEFAULT_SUBCATEGORY (jtrace, bindings, "TRACE for Java(TM)");
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_trace_Trace_hostStateDeclare(JNIEnv * env, jclass cls, jstring js)
+{
+ const char *s = (*env)->GetStringUTFChars(env, js, 0);
+ TRACE_host_state_declare(s);
+ (*env)->ReleaseStringUTFChars(env, js, s);
+}
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_trace_Trace_hostStateDeclareValue
+ (JNIEnv *env, jclass cls, jstring js_state, jstring js_value, jstring js_color)
+{
+ const char *state = (*env)->GetStringUTFChars(env, js_state, 0);
+ const char *value = (*env)->GetStringUTFChars(env, js_value, 0);
+ const char *color = (*env)->GetStringUTFChars(env, js_color, 0);
+
+ TRACE_host_state_declare_value(state, value, color);
+
+ (*env)->ReleaseStringUTFChars(env, js_state, state);
+ (*env)->ReleaseStringUTFChars(env, js_value, value);
+ (*env)->ReleaseStringUTFChars(env, js_color, color);
+}
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_trace_Trace_hostSetState
+ (JNIEnv *env, jclass cls, jstring js_host, jstring js_state, jstring js_value)
+{
+ const char *host = (*env)->GetStringUTFChars(env, js_host, 0);
+ const char *state = (*env)->GetStringUTFChars(env, js_state, 0);
+ const char *value = (*env)->GetStringUTFChars(env, js_value, 0);
+
+ TRACE_host_set_state(host, state, value);
+
+ (*env)->ReleaseStringUTFChars(env, js_host, host);
+ (*env)->ReleaseStringUTFChars(env, js_state, state);
+ (*env)->ReleaseStringUTFChars(env, js_value, value);
+}
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_trace_Trace_hostPushState
+ (JNIEnv *env, jclass cls, jstring js_host, jstring js_state, jstring js_value)
+{
+ const char *host = (*env)->GetStringUTFChars(env, js_host, 0);
+ const char *state = (*env)->GetStringUTFChars(env, js_state, 0);
+ const char *value = (*env)->GetStringUTFChars(env, js_value, 0);
+
+ TRACE_host_push_state(host, state, value);
+
+ (*env)->ReleaseStringUTFChars(env, js_host, host);
+ (*env)->ReleaseStringUTFChars(env, js_state, state);
+ (*env)->ReleaseStringUTFChars(env, js_value, value);
+}
+
+JNIEXPORT void JNICALL
+Java_org_simgrid_trace_Trace_hostPopState
+ (JNIEnv *env, jclass cls, jstring js_host, jstring js_state)
+{
+ const char *host = (*env)->GetStringUTFChars(env, js_host, 0);
+ const char *state = (*env)->GetStringUTFChars(env, js_state, 0);
+
+ TRACE_host_pop_state(host, state);
+
+ (*env)->ReleaseStringUTFChars(env, js_host, host);
+ (*env)->ReleaseStringUTFChars(env, js_state, state);
+}
--- /dev/null
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class org_simgrid_trace_Trace */
+
+#ifndef _Included_org_simgrid_trace_Trace
+#define _Included_org_simgrid_trace_Trace
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: hostVariableDeclare
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_hostVariableDeclare
+ (JNIEnv *, jclass, jstring);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: hostVariableDeclareWithColor
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_hostVariableDeclareWithColor
+ (JNIEnv *, jclass, jstring, jstring);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: hostVariableSet
+ * Signature: (Ljava/lang/String;Ljava/lang/String;D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_hostVariableSet
+ (JNIEnv *, jclass, jstring, jstring, jdouble);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: hostVariableAdd
+ * Signature: (Ljava/lang/String;Ljava/lang/String;D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_hostVariableAdd
+ (JNIEnv *, jclass, jstring, jstring, jdouble);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: hostVariableSub
+ * Signature: (Ljava/lang/String;Ljava/lang/String;D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_hostVariableSub
+ (JNIEnv *, jclass, jstring, jstring, jdouble);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: hostVariableSetWithTime
+ * Signature: (DLjava/lang/String;Ljava/lang/String;D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_hostVariableSetWithTime
+ (JNIEnv *, jclass, jdouble, jstring, jstring, jdouble);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: hostVariableAddWithTime
+ * Signature: (DLjava/lang/String;Ljava/lang/String;D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_hostVariableAddWithTime
+ (JNIEnv *, jclass, jdouble, jstring, jstring, jdouble);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: hostVariableSubWithTime
+ * Signature: (DLjava/lang/String;Ljava/lang/String;D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_hostVariableSubWithTime
+ (JNIEnv *, jclass, jdouble, jstring, jstring, jdouble);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: getHostVariablesName
+ * Signature: ()[Ljava/lang/String;
+ */
+JNIEXPORT jobjectArray JNICALL Java_org_simgrid_trace_Trace_getHostVariablesName
+ (JNIEnv *, jclass);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: linkVariableDeclare
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_linkVariableDeclare
+ (JNIEnv *, jclass, jstring);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: linkVariableDeclareWithColor
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_linkVariableDeclareWithColor
+ (JNIEnv *, jclass, jstring, jstring);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: linkVariableSet
+ * Signature: (Ljava/lang/String;Ljava/lang/String;D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_linkVariableSet
+ (JNIEnv *, jclass, jstring, jstring, jdouble);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: linkVariableAdd
+ * Signature: (Ljava/lang/String;Ljava/lang/String;D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_linkVariableAdd
+ (JNIEnv *, jclass, jstring, jstring, jdouble);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: linkVariableSub
+ * Signature: (Ljava/lang/String;Ljava/lang/String;D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_linkVariableSub
+ (JNIEnv *, jclass, jstring, jstring, jdouble);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: linkVariableSetWithTime
+ * Signature: (DLjava/lang/String;Ljava/lang/String;D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_linkVariableSetWithTime
+ (JNIEnv *, jclass, jdouble, jstring, jstring, jdouble);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: linkVariableAddWithTime
+ * Signature: (DLjava/lang/String;Ljava/lang/String;D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_linkVariableAddWithTime
+ (JNIEnv *, jclass, jdouble, jstring, jstring, jdouble);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: linkVariableSubWithTime
+ * Signature: (DLjava/lang/String;Ljava/lang/String;D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_linkVariableSubWithTime
+ (JNIEnv *, jclass, jdouble, jstring, jstring, jdouble);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: linkSrcDstVariableSet
+ * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_linkSrcDstVariableSet
+ (JNIEnv *, jclass, jstring, jstring, jstring, jdouble);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: linkSrcDstVariableAdd
+ * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_linkSrcDstVariableAdd
+ (JNIEnv *, jclass, jstring, jstring, jstring, jdouble);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: linkSrcDstVariableSub
+ * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_linkSrcDstVariableSub
+ (JNIEnv *, jclass, jstring, jstring, jstring, jdouble);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: linkSrcDstVariableSetWithTime
+ * Signature: (DLjava/lang/String;Ljava/lang/String;Ljava/lang/String;D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_linkSrcDstVariableSetWithTime
+ (JNIEnv *, jclass, jdouble, jstring, jstring, jstring, jdouble);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: linkSrcdstVariableAddWithTime
+ * Signature: (DLjava/lang/String;Ljava/lang/String;Ljava/lang/String;D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_linkSrcdstVariableAddWithTime
+ (JNIEnv *, jclass, jdouble, jstring, jstring, jstring, jdouble);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: linkSrcDstVariableSubWithTime
+ * Signature: (DLjava/lang/String;Ljava/lang/String;Ljava/lang/String;D)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_linkSrcDstVariableSubWithTime
+ (JNIEnv *, jclass, jdouble, jstring, jstring, jstring, jdouble);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: getLinkVariablesName
+ * Signature: ()[Ljava/lang/String;
+ */
+JNIEXPORT jobjectArray JNICALL Java_org_simgrid_trace_Trace_getLinkVariablesName
+ (JNIEnv *, jclass);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: hostStateDeclare
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_hostStateDeclare
+ (JNIEnv *, jclass, jstring);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: hostStateDeclareValue
+ * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_hostStateDeclareValue
+ (JNIEnv *, jclass, jstring, jstring, jstring);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: hostSetState
+ * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_hostSetState
+ (JNIEnv *, jclass, jstring, jstring, jstring);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: hostPushState
+ * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_hostPushState
+ (JNIEnv *, jclass, jstring, jstring, jstring);
+
+/*
+ * Class: org_simgrid_trace_Trace
+ * Method: hostPopState
+ * Signature: (Ljava/lang/String;Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_simgrid_trace_Trace_hostPopState
+ (JNIEnv *, jclass, jstring, jstring);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
--- /dev/null
+/* context_cojava - implementation of context switching for java coroutines */
+
+/* Copyright 2012. The SimGrid Team.
+ * All rights reserved. */
+
+/* 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 <xbt/function_types.h>
+#include <simgrid/simix.h>
+#include <xbt/ex.h>
+#include "smx_context_cojava.h"
+#include "jxbt_utilities.h"
+#include "xbt/dynar.h"
+
+
+//Coroutine methodID/class cache.
+jclass coclass;
+jmethodID coroutine_init;
+jmethodID coroutine_yield;
+jmethodID coroutine_yieldTo;
+jmethodID coroutine_stop;
+//Maestro java coroutine
+jobject cojava_maestro_coroutine;
+
+JNIEnv *global_env;
+
+static smx_context_t my_current_context = NULL;
+static smx_context_t maestro_context = NULL;
+
+
+xbt_dynar_t cojava_processes;
+static unsigned long int cojava_process_index = 0;
+
+extern JavaVM *__java_vm;
+
+XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg);
+
+
+static smx_context_t
+smx_ctx_cojava_factory_create_context(xbt_main_func_t code, int argc,
+ char **argv,
+ void_pfn_smxprocess_t cleanup_func,
+ void *data);
+
+static void smx_ctx_cojava_free(smx_context_t context);
+static void smx_ctx_cojava_start(smx_context_t context);
+static void smx_ctx_cojava_suspend(smx_context_t context);
+static void smx_ctx_cojava_resume(smx_context_t new_context);
+static void smx_ctx_cojava_runall(void);
+static void* smx_ctx_cojava_run(void *data);
+static void smx_ctx_cojava_create_coroutine(smx_ctx_cojava_t context);
+void SIMIX_ctx_cojava_factory_init(smx_context_factory_t * factory)
+{
+ /* instantiate the context factory */
+ smx_ctx_base_factory_init(factory);
+
+ (*factory)->create_context = smx_ctx_cojava_factory_create_context;
+ /* Leave default behavior of (*factory)->finalize */
+ (*factory)->free = smx_ctx_cojava_free;
+ (*factory)->stop = smx_ctx_cojava_stop;
+ (*factory)->suspend = smx_ctx_cojava_suspend;
+ (*factory)->runall = smx_ctx_cojava_runall;
+ (*factory)->name = "ctx_cojava_factory";
+ //(*factory)->finalize = smx_ctx_base_factory_finalize;
+ (*factory)->self = smx_ctx_cojava_self;
+ (*factory)->get_data = smx_ctx_base_get_data;
+
+ global_env = get_current_thread_env();
+
+ coclass = (*global_env)->FindClass(global_env, "java/dyn/Coroutine");
+ xbt_assert((coclass != NULL), "Can't find java.dyn.Coroutine class.");
+ //Cache the method id we are going to use
+ coroutine_init = (*global_env)->GetMethodID(global_env, coclass, "<init>", "(Ljava/lang/Runnable;)V");
+ xbt_assert((coroutine_init != NULL), "Can't find <init>");
+ coroutine_stop = (*global_env)->GetMethodID(global_env, coclass, "stop", "()V");
+ xbt_assert((coroutine_stop != NULL), "Method not found...");
+ coroutine_yield = (*global_env)->GetStaticMethodID(global_env, coclass, "yield", "()V");
+ xbt_assert((coroutine_yield != NULL), "Method yield not found.");
+ coroutine_yieldTo = (*global_env)->GetStaticMethodID(global_env, coclass, "yieldTo", "(Ljava/dyn/Coroutine;)V");
+ xbt_assert((coroutine_yieldTo != NULL), "Method yieldTo not found.");
+
+ 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;");
+ xbt_assert((thread_get_current != NULL), "Can't find Thread.currentThread() method.");
+
+ /**
+ * Retrieve maetro coroutine object
+ */
+ jobject jthread;
+ jthread = (*global_env)->CallStaticObjectMethod(global_env, class_thread, thread_get_current);
+ xbt_assert((jthread != NULL), "Can't find current thread.");
+
+ jmethodID thread_get_coroutine_support = (*global_env)->GetMethodID(global_env, class_thread, "getCoroutineSupport", "()Ljava/dyn/CoroutineSupport;");
+ xbt_assert((thread_get_coroutine_support != NULL), "Can't find Thread.getCoroutineSupport method");
+
+ jobject jcoroutine_support;
+ jcoroutine_support = (*global_env)->CallObjectMethod(global_env, jthread, thread_get_coroutine_support);
+ xbt_assert((jcoroutine_support != NULL), "Can't find coroutine support object");
+ //FIXME ? Be careful, might change in the implementation (we are relying on private fields, so...).
+ jfieldID coroutine_support_thread_coroutine = (*global_env)->GetFieldID(global_env, class_coroutine_support, "threadCoroutine", "Ljava/dyn/Coroutine;");
+ xbt_assert((coroutine_support_thread_coroutine != NULL), "Can't find threadCoroutine field");
+ cojava_maestro_coroutine = (jobject)(*global_env)->GetObjectField(global_env, jcoroutine_support, coroutine_support_thread_coroutine);
+ xbt_assert((cojava_maestro_coroutine != NULL), "Can't find the thread coroutine.");
+ cojava_maestro_coroutine = (*global_env)->NewGlobalRef(global_env, cojava_maestro_coroutine);
+ xbt_assert((cojava_maestro_coroutine != NULL), "Can't get a global reference to the thread coroutine.");
+}
+smx_context_t smx_ctx_cojava_self(void)
+{
+ return my_current_context;
+}
+
+static smx_context_t
+smx_ctx_cojava_factory_create_context(xbt_main_func_t code, int argc,
+ char **argv,
+ void_pfn_smxprocess_t cleanup_func,
+ void* data)
+{
+ smx_ctx_cojava_t context = xbt_new0(s_smx_ctx_cojava_t, 1);
+ /* If the user provided a function for the process then use it
+ otherwise is the context for maestro */
+ if (code) {
+ if (argc == 0) {
+ context->jprocess = (jobject) code;
+ }
+ else {
+ context->jprocess = NULL;
+ }
+ context->super.cleanup_func = cleanup_func;
+
+ context->super.argc = argc;
+ context->super.argv = argv;
+ context->super.code = code;
+
+ smx_ctx_cojava_run(context);
+ }
+ else {
+ context->jcoroutine = NULL;
+ my_current_context = (smx_context_t)context;
+ maestro_context = (smx_context_t)context;
+ }
+ context->bound = 0;
+ context->super.data = data;
+ return (smx_context_t) context;
+}
+
+static void* smx_ctx_cojava_run(void *data) {
+ smx_ctx_cojava_t context = (smx_ctx_cojava_t)data;
+ my_current_context = (smx_context_t)context;
+ //Create the "Process" object if needed.
+ if (context->super.argc <= 0) {
+ smx_ctx_cojava_create_coroutine(context);
+ }
+ my_current_context = maestro_context;
+ return NULL;
+}
+static void smx_ctx_cojava_free(smx_context_t context)
+{
+ if (context) {
+ smx_ctx_cojava_t ctx_java = (smx_ctx_cojava_t) context;
+ if (ctx_java->jcoroutine) { /* We are not in maestro context */
+ JNIEnv *env = get_current_thread_env();
+ (*env)->DeleteGlobalRef(env, ctx_java->jcoroutine);
+ (*env)->DeleteGlobalRef(env, ctx_java->jprocess);
+ }
+ }
+ smx_ctx_base_free(context);
+}
+
+
+void smx_ctx_cojava_stop(smx_context_t context)
+{
+ /*
+ * The java stack needs to be empty, otherwise weird stuff
+ * will happen
+ */
+ if (context->iwannadie) {
+ context->iwannadie = 0;
+ JNIEnv *env = get_current_thread_env();
+ jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", bprintf("Process killed :)"));
+ THROWF(cancel_error, 0, "process cancelled");
+ }
+ else {
+ smx_ctx_base_stop(context);
+ smx_ctx_cojava_suspend(context);
+ }
+}
+
+static void smx_ctx_cojava_suspend(smx_context_t context)
+{
+ smx_context_t previous_context = context;
+ unsigned long int i = cojava_process_index++;
+ jobject next_coroutine;
+
+ if (i < xbt_dynar_length(cojava_processes)) {
+ smx_context_t next_context = SIMIX_process_get_context(xbt_dynar_get_as(
+ cojava_processes,i, smx_process_t));
+ my_current_context = next_context;
+ XBT_DEBUG("Switching to %p",my_current_context);
+ smx_ctx_cojava_t java_context = (smx_ctx_cojava_t)(next_context);
+
+ if (!java_context->jprocess) {
+ (*(java_context->super.code))(java_context->super.argc, java_context->super.argv);
+ smx_ctx_cojava_create_coroutine(java_context);
+ }
+ else if (!java_context->bound) {
+ java_context->bound = 1;
+ smx_process_t process = SIMIX_process_self();
+ (*global_env)->SetLongField(global_env, java_context->jprocess, jprocess_field_Process_bind, (jlong)process);
+ }
+
+ next_coroutine = java_context->jcoroutine;
+ }
+ else {
+ //Give maestro the control back.
+ next_coroutine = cojava_maestro_coroutine;
+ my_current_context = maestro_context;
+ }
+ (*global_env)->CallStaticVoidMethod(global_env, coclass, coroutine_yieldTo, next_coroutine);
+ my_current_context = previous_context;
+}
+
+static void smx_ctx_cojava_resume(smx_context_t new_context) {
+ my_current_context = new_context;
+ smx_ctx_cojava_t java_context = (smx_ctx_cojava_t)(new_context);
+
+ if (!java_context->jprocess) {
+ (*(java_context->super.code))(java_context->super.argc, java_context->super.argv);
+ smx_ctx_cojava_create_coroutine(java_context);
+ java_context->bound = 1;
+ }
+ else if (!java_context->bound) {
+ java_context->bound = 1;
+ smx_process_t process = SIMIX_process_self();
+ (*global_env)->SetLongField(global_env, java_context->jprocess, jprocess_field_Process_bind, (jlong)process);
+ }
+ (*global_env)->CallStaticVoidMethod(global_env, coclass, coroutine_yieldTo, java_context->jcoroutine);
+}
+
+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));
+}
+
+static void smx_ctx_cojava_create_coroutine(smx_ctx_cojava_t context) {
+ JNIEnv *env = get_current_thread_env();
+ 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.");
+ jcoroutine = (*env)->NewGlobalRef(env, jcoroutine);
+ context->jcoroutine = jcoroutine;
+}
--- /dev/null
+/* Copyright (c) 2012. The SimGrid Team.
+ * All rights reserved. */
+
+/* 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. */
+
+#ifndef _XBT_CONTEXT_COJAVA_H
+#define _XBT_CONTEXT_COJAVA_H
+
+#include <xbt/misc.h>
+#include <simgrid/simix.h>
+#include <xbt/xbt_os_thread.h>
+
+#include "jmsg.h"
+#include "jmsg_process.h"
+
+SG_BEGIN_DECL()
+
+typedef struct s_smx_ctx_cojava {
+ s_smx_ctx_base_t super; /* Fields of super implementation */
+ jobject jprocess; /* the java process instance binded with the msg process structure */
+ JNIEnv *jenv; /* jni interface pointer associated to this thread */
+ jobject jcoroutine; /* java coroutine object */
+ int bound:1;
+} s_smx_ctx_cojava_t, *smx_ctx_cojava_t;
+
+void SIMIX_ctx_cojava_factory_init(smx_context_factory_t *factory);
+void smx_ctx_cojava_stop(smx_context_t context);
+smx_context_t smx_ctx_cojava_self(void);
+SG_END_DECL()
+
+#endif /* !_XBT_CONTEXT_JAVA_H */
-/* 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