Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge commit '4df273f15273f959fc9e6ed69d2bf5e607ec9bf7' into HEAD
authorPaul Bédaride <paul.bedaride@gmail.com>
Wed, 30 Jan 2013 17:20:59 +0000 (18:20 +0100)
committerPaul Bédaride <paul.bedaride@gmail.com>
Wed, 30 Jan 2013 17:20:59 +0000 (18:20 +0100)
40 files changed:
CMakeLists.txt
COPYING [new file with mode: 0644]
ChangeLog
FindJavaSG.cmake
MANIFEST.MF [new file with mode: 0644]
doc/install.doc
examples/async/async.tesh
examples/bittorrent/bittorrent.tesh
examples/chord/chord.tesh
examples/cloud/Cloud.java
examples/cloud/cloud.tesh
examples/commTime/commtime.tesh
examples/kademlia/kademlia.tesh
examples/master_slave_bypass/bypass.tesh
examples/master_slave_kill/kill.tesh
examples/masterslave/masterslave.tesh
examples/migration/migration.tesh
examples/mutualExclusion/mutualexclusion.tesh
examples/pingPong/pingpong.tesh
examples/priority/priority.tesh
examples/startKillTime/startKillTime.tesh
examples/suspend/suspend.tesh
examples/tracing/TracingTest.java
examples/tracing/tracingPingPong.tesh
org/simgrid/msg/Comm.java
org/simgrid/msg/File.java
org/simgrid/msg/Host.java
org/simgrid/msg/JniException.java
org/simgrid/msg/Msg.java
org/simgrid/msg/Mutex.java
org/simgrid/msg/Process.java
org/simgrid/msg/RngStream.java
org/simgrid/msg/Task.java
org/simgrid/trace/Trace.java
src/jmsg.c
src/jmsg.h
src/jmsg_process.c
src/jmsg_process.h
src/smx_context_cojava.c
src/smx_context_java.c

index 34b5cee..e1cf067 100644 (file)
@@ -7,8 +7,8 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_HOME_DIRECTORY}/lib")
 set(soversion 1)
 
 set(SIMGRID_JAVA_VERSION_MAJOR "3")
-set(SIMGRID_JAVA_VERSION_MINOR "7")
-set(SIMGRID_JAVA_VERSION_PATCH "1")
+set(SIMGRID_JAVA_VERSION_MINOR "9")
+set(SIMGRID_JAVA_VERSION_PATCH "0")
 set(DIST_NAME ${PROJECT_NAME}-${SIMGRID_JAVA_VERSION_MAJOR}.${SIMGRID_JAVA_VERSION_MINOR}.${SIMGRID_JAVA_VERSION_PATCH})
 
 ########
@@ -156,6 +156,7 @@ set(JAVA_EXAMPLES
   ${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/cloud/Cloud.java
   ${CMAKE_HOME_DIRECTORY}/examples/cloud/FinalizeTask.java
@@ -221,6 +222,8 @@ set(JAVA_TRACING_EXAMPLES
 
 set(CMAKE_SRC
   ${CMAKE_HOME_DIRECTORY}/ChangeLog
+  ${CMAKE_HOME_DIRECTORY}/MANIFEST.MF
+  ${CMAKE_HOME_DIRECTORY}/COPYING
   ${CMAKE_HOME_DIRECTORY}/CMakeLists.txt
   ${CMAKE_HOME_DIRECTORY}/doxygen_postprocesser.pl
   ${CMAKE_HOME_DIRECTORY}/FindJavaSG.cmake
@@ -370,6 +373,17 @@ if(HAVE_TRACING)
   )
 endif(HAVE_TRACING)
 
+IF(CMAKE_SYSTEM_PROCESSOR MATCHES ".86")
+  IF(${ARCH_32_BITS})
+      set(JSG_BUNDLE NATIVE/${CMAKE_SYSTEM_NAME}/x86/)
+  ELSE()
+      set(JSG_BUNDLE NATIVE/${CMAKE_SYSTEM_NAME}/amd64/)
+  ENDIF()
+ELSE() 
+  error("Unknown system type. Processor: ${CMAKE_SYSTEM_PROCESSOR}; System: ${CMAKE_SYSTEM_NAME}")
+ENDIF()
+message("Native libraries bundeled into: ${JSG_BUNDLE}")
+
 # java_classes
 add_custom_command(
   OUTPUT  ${JAVA_SRC_CLASS}
@@ -377,6 +391,13 @@ add_custom_command(
   COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_HOME_DIRECTORY}/classes/"
   COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/classes/
     -cp ${CMAKE_HOME_DIRECTORY}/classes/ ${JAVA_SRC}
+  COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_HOME_DIRECTORY}/classes/${JSG_BUNDLE}
+  COMMAND ${CMAKE_COMMAND} -E copy ${SIMGRID_LIB_PATH}/libsimgrid.so ${CMAKE_HOME_DIRECTORY}/classes/${JSG_BUNDLE}
+  COMMAND strip --strip-debug ${CMAKE_HOME_DIRECTORY}/classes/${JSG_BUNDLE}/libsimgrid.so
+  COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/lib/libSG_java.so ${CMAKE_HOME_DIRECTORY}/classes/${JSG_BUNDLE}
+  COMMAND strip --strip-debug ${CMAKE_HOME_DIRECTORY}/classes/${JSG_BUNDLE}/libSG_java.so
+  COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/ChangeLog ${CMAKE_HOME_DIRECTORY}/classes/${JSG_BUNDLE}
+  COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_HOME_DIRECTORY}/COPYING ${CMAKE_HOME_DIRECTORY}/classes/${JSG_BUNDLE}
   COMMENT "Compiling java sources of core library..."                                  
 )
 
@@ -386,7 +407,7 @@ add_custom_target(java_classes ALL
 
 # simgrid_jar
 add_custom_target(simgrid_jar ALL
-  COMMAND ${JAVA_ARCHIVE} -cvf ${CMAKE_HOME_DIRECTORY}/simgrid.jar .
+  COMMAND ${JAVA_ARCHIVE} -cmvf ${CMAKE_HOME_DIRECTORY}/MANIFEST.MF ${CMAKE_HOME_DIRECTORY}/simgrid.jar .
   COMMENT "Building simgrid.jar..."
   WORKING_DIRECTORY ${CMAKE_HOME_DIRECTORY}/classes 
 )
diff --git a/COPYING b/COPYING
new file mode 100644 (file)
index 0000000..a13f68b
--- /dev/null
+++ b/COPYING
@@ -0,0 +1,9 @@
+All of the Java bindings to the SimGrid software was written
+internally by the team. This software is distributed under the GNU
+lesser general public license version 2.1, which you can find in the
+archive under the name LICENSE-LGPL-2.1.
+
+For any copyright year range specified as YYYY-ZZZZ in this package
+note that the range specifies every single year in that closed interval.
+
+The SimGrid logo is distributed under the CC-BY-SA license.
index 8402234..2ef1989 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,19 +1,27 @@
-SimGrid-java (3.8) unstable; urgency=low
+SimGrid-java (3.8.1) 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). 
- Extend the API:
+ * New module: org.simgrid.trace.Trace (SimGrid trace bindings)
+   Warning: all methods are visible, but only some of them are 
+   implemented so far. Check the source (src/jtrace.c)
+   for further information.
  * New module: org.simgrid.msg.File (SimGrid File management functions)
- * New Module: org.simgrid.msg.VM (SimGrid interface to mimick IAAS 
-clouds)
- * Change the meaning of Process.restart: now restart the process from the start, like MSG_process_restart in C.
- * Add Process.setAutoRestart: handling of process restart when failed host comes back.
- * Add Process.getProperty, Host.getProperty, Host.getProperty: allows you to retrieve the properties of the processes/hosts
+ * New Module: org.simgrid.msg.VM (SimGrid interface to mimick IAAS clouds)
+ * Change the meaning of Process.restart: now restart the process from
+   the begining, like MSG_process_restart in C.
+ * Add Process.setAutoRestart: handling of process restart when failed
+   host comes back. 
+ * Add Process.getProperty, Host.getProperty, Host.getProperty: allows
+   you to retrieve the properties of the processes/hosts
+ * Deprecate Msg.clean(): you can just forget about it now.
+ * New function Process.getCount(), that only works when compiling
+   with the not yet released version 3.9 of the C library.
  
- * Introduce a new context factory based on Coroutines (read the doc to know how to use it): simulations are expected to run up to five times faster.
+ * New context factory based on Coroutines. It mandates a modified JVM
+   but then, the simulations run about five times faster, and there is
+   no limit to the amount of processes (beside of the available memory).
+
+ -- 2012-12-04 Da SimGrid team <simgrid-devel@lists.gforge.inria.fr>
+
 SimGrid-java (3.7.1) stable; urgency=low
   
  The "Java aint got to be bloated and slow" release
index 92d254d..47bddfd 100644 (file)
@@ -1,6 +1,9 @@
+set(JAVA_INCLUDE_PATH "$ENV{JAVA_INCLUDE_PATH}")
+set(JAVA_INCLUDE_PATH2 "$ENV{JAVA_INCLUDE_PATH}")
+
 include(FindJava)
 include(FindJNI)
-       
+
 message(STATUS "Looking for jni.h")
 if(JAVA_INCLUDE_PATH)
  message(STATUS "Looking for jni.h - found")
diff --git a/MANIFEST.MF b/MANIFEST.MF
new file mode 100644 (file)
index 0000000..8d2c039
--- /dev/null
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Built-By: Da SimGrid team
+Main-Class: org.simgrid.msg.Msg
+Class-Path: .
+
index 853ac8a..0dc293c 100644 (file)
@@ -3,11 +3,13 @@
 \section bindings_binding_java_install How to install Simgrid-java
 
 To use java with Simgrid you have to install some dependencies:
- \li Simgrid (see <a href="http://simgrid.gforge.inria.fr/simgrid/3.7/doc/install.html">install
+ \li Simgrid (see <a href="http://simgrid.gforge.inria.fr/simgrid/latest/doc/install.html">install
      Simgrid</a>). You should set the SIMGRID_ROOT environment
      variable to the path where you installed SimGrid.
- \li Java JDK packages, such as sun-java6-jdk (with libgcj10-dev or
-another version of gcj) or openjdk6.
+ \li Java JDK packages, such as openjdk7 or sun-java6-jdk (with
+     libgcj10-dev or another version of gcj). For maximal performance
+     and scalability, use a coroutine-enabled JVM (see
+     \ref bindings_binding_java_coroutines).
  
 Then Download and install package Simgrid-java:
 \verbatim
@@ -23,7 +25,7 @@ Cmake output
 -- BUILDNAME   : Simgrid-Java
 -- Looking for lib SimGrid
 -- Looking for lib SimGrid - found
--- Simgrid version : 3.6
+-- Simgrid version : 3.8.1
 -- Looking for gras.h
 -- Looking for gras.h - found
 -- Found Tesh: /home/user/Bureau/simgrid/git/bin/tesh
@@ -41,6 +43,27 @@ Cmake output
 -- Build files have been written to: /home/user/workspace/simgrid-java/build
 \endverbatim
 
+If cmake complains that <b>jni could not be found</b>, you need to
+tell it where JNI header files are located. the following command
+should tell you:
+
+\verbatim
+$ locate jni.h
+/usr/lib/jvm/java-6-openjdk-amd64/include/jni.h
+/usr/lib/jvm/java-7-openjdk-amd64/include/jni.h
+\endverbatim
+
+If you have several version of jni installed (as in the example
+above), you need to check the version of java that is used by default
+on your machine (using javac -version), and pick the right one. Then
+set the JAVA_INCLUDE_PATH environment variable to the right path (note
+that we remove the filename jni.h from that path), and relaunch cmake.
+
+\verbatim
+$ export JAVA_INCLUDE_PATH=/usr/lib/jvm/java-6-openjdk-amd64/include/
+$ cmake .
+\endverbatim
+
 \section bindings_binding_java_use How to use Simgrid-java
 
 To execute the examples you need to add the path where you installed
@@ -51,30 +74,152 @@ Be careful on Mac, this variable is called DYLD_LIBRARY_PATH and not
 LD_LIBRARY_PATH.
 
 \verbatim
-$ export SIMGRID_ROOT="$HOME/Install/simgrid/"
-$ export SIMGRID_JAVA_ROOT="$HOME/Install/simgrid-java"
-$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SIMGRID_ROOT/lib:$SIMGRID_JAVA_ROOT/java
+$ export SIMGRID_ROOT="$HOME/Install/simgrid/" # change it to the path where you installed the SimGrid library
+$ export SIMGRID_JAVA_ROOT="$HOME/Install/simgrid-java" # change it to the path where you installed the java bindings of SimGrid 
+$ export LD_LIBRARY_PATH=${LD_LIBRARY_PATH:+$LD_LIBRARY_PATH:}$SIMGRID_ROOT/lib:$SIMGRID_JAVA_ROOT/java
 $ cd examples
 $ java -cp .:../simgrid.jar basic/BasicTest platform.xml basic/basicDeployment.xml
 \endverbatim
 
+If you want to make these settings permanent even after a reboot, you
+need to add the export lines into your ~/.bashrc file, or equivalent.
+
+
+
+
 \section bindings_binding_java_coroutines How to use the coroutines context factory
 
-You may want to use the coroutines context factory, if speed maters to you (since it's about 5 times faster than the default thread-based context factory).
+There is two main motivations to use the coroutine variant of SimGrid
+Java bindings: it's about 5 times faster than the default thread-based
+context factory, and the amount of runnable processes is then only
+limited by the amount of RAM that you have. The drawbacks are that it
+requires a specific and rather experimental JVM to run, and that this
+context factory itself remains a bit experimental so far.
+
+\subsection  bindings_java_coro_install Getting a mlvm JVM
+
+You need to get a patched JVM from <a href="http://ssw.jku.at/General/Staff/LS/coro/">here</a>
+(many thanks to Lukas Stadler for this work!). 
+
+You can either get a prebuilt binary, or recompile your own JVM. Make
+sure to get a coro-simple version, as we don't need to serialize nor
+migrate stacks in SimGrid. You should be able to follow the README.txt
+that you'll get in the repository, but here is how we did it, just in
+case. The instructions are given for a debian or Ubuntu box, but I
+think you should manage to convert it to your system quite easily.
+Finally, if you're really stuck, you can get the version compiled by
+Jonathan Rouzaud-Cornabas from his web page. This version is known to
+work with SimGrid for sure!
+http://graal.ens-lyon.fr/~jrouzaud/files/corosimple-linux-amd64-20120914.tgz
+ -# Install mercurial and some dependencies
+\verbatim 
+sudo apt-get install mercurial ksh libfreetype6-dev libcups2-dev libasound2-dev gawk openjdk-7-jdk libxext-dev libxrender-dev libxtst-dev
+# Grab the forest extension: we need to source-install it
+hg clone https://bitbucket.org/gxti/hgforest hgforest \endverbatim
+\endverbatim
+ -# Configure the mercurial extensions: Edit ~/.hgrc and paste the
+    following lines. Don't forget to change the /path/to/forest.py to
+    point to where you just downloaded the source. 
+    
+    Forest extension is needed to download the openjdk source code and
+    patches while the mq line is needed to apply the patches. The
+    username is needed at the step "preparing the sources", not sure why.
+\verbatim
+[ui]
+username = YouUserameWithoutSpaces
+[extensions]
+forest=/path/to/forest.py
+mq=
+\endverbatim
+ -# Prepare the source code
+\verbatim 
+# create a working directory, and enter it
+mkdir davinci; cd davinci
+
+# Grab the sources
+hg fclone http://hg.openjdk.java.net/hsx/hotspot-comp sources
+# Grab the patches
+hg fclone http://hg.openjdk.java.net/mlvm/mlvm patches
+
+# Link the patch directories into the sources
+bash patches/make/link-patch-dirs.sh sources patches
+# Test wether the previous command worked with
+ls -i patches/hotspot/series sources/hotspot/.hg/patches/series
+# It should display something like the following.
+# (note that both file share the same inode number)
+#  9707849 patches/hotspot/series  
+#  9707849 sources/hotspot/.hg/patches/series
+
+
+# Specify what to compile. 
+export davinci=$(pwd) guards="buildable testable coro-simple"
+# Apply the patches
+sh patches/make/each-patch-repo.sh hg qselect --reapply $guards '$(sh $davinci/patches/make/current-release.sh)'
+# Check that it understood that you want the patch applied:
+grep GLOBAL_GUARDS patches/make/* -r
+# this should display something like the following (maybe amonst other unrelated lines)
+# GLOBAL_GUARDS=buildable testable coro-simple
+# If this does not work, edit patches/make/Makefile,
+#   manually coro-simple to GLOBAL_GUARDS and then 
+#   rerun the patches/make/each-patch-repo.sh script as earlier
+
 
-First, remember that the coroutines context factory is still experimental work.
+# Finish the setup
+(cd patches/make; make setup && make force && make && make FORCE_VERSIONS=1 && echo "Sources are properly setup")
+# If this last command failed, check your mercurial config within ~/.hgrc (see above)
+\endverbatim          
+ -# Compile it all
+\verbatim
+unset LD_LIBRARY_PATH
+export ALT_BOOTDIR=/usr/lib/jvm/java-7-openjdk-amd64/
+cd sources
+# Check that everything is fine
+make sanity
+# Go for it (it takes about half an hour on my machine)
+make all
 
-To use the coroutines context factory, you need a Java virtual machine which supports it.
+# Check that the coroutine library got compiled in
+ls sources/build/linux-amd64/classes/java/dyn/
+# This should display a bunch of class files. If not, something went wrong, you need to investigate further
+\endverbatim
 
-Our implementation rely on a JVM patch made by Lukas Stadler, which you can find <a href="http://ssw.jku.at/General/Staff/LS/coro/">here</a>. You can either recompile the JVM yourself or use the pre-built binaries offered.
+\subsection  bindings_java_coro_use Using coroutine contexts
 
-SimGrid Java will automatically switch to the coroutine context factory if your JVM support it, so you will just need to execute your simulation with the correct JVM:
+SimGrid Java will automatically switch to the coroutine context
+factory if your JVM support it, so you will just need to execute your
+simulation with the correct JVM. The selected context factory gets
+displayed automatically.
 \verbatim
-$ $PATH_TO_COROUTINE_JVM/java -cp .:../simgrid.jar basic/BasicTest platform.xml basic/basicDeployment.xml
+export LD_LIBRARY_PATH=/path/to/simgrid.so:/path/to/libSG_java.so
+cd examples
+$PATH_TO_COROUTINE_JVM/java -cp .:../simgrid.jar masterslave.Masterslave masterslave/ masterslaveDeployment.xml platform.xml
 \endverbatim
 
-Notice that you may have to adjust the "coro.stacksPerThread" configuration option to run large simulations:
+Note that you may have to adjust the "coro.stacksPerThread"
+configuration option to run large simulations. The default is 100 and
+you want to increase it to run more processes.
 \verbatim
 $ $PATH_TO_COROUTINE_JVM/java -Dcoro.stacksPerThread=$STACKS_NUMBER -cp .:../simgrid.jar basic/BasicTest platform.xml basic/basicDeployment.xml
-\endverbatim 
+\endverbatim
+
+If you reach the point where the creation of new simulated processes
+fail with the message "Can't create coroutine object", you may need to
+increase the relevant system limit with the following command.
+\verbatim 
+sysctl -w vm.max_map_count = 131072
+\endverbatim
+
+The full story is that each coroutine requires two memory maps, and
+that Linux puts a limit on the total amount of memory maps that each
+process can manage (by default, this limit is often at 65535). Since
+the JVM needs a few dozen of such maps on its own (three maps per
+dynamic library -- check /proc/the_pid/maps if you don't believe it),
+this is enough to create over 30,000 simulated processes. But to go
+futher, that limit must be modified. 
+
+If you want to make this change permanent on your machine, edit your
+/etc/sysctl.conf file. Otherwise, you have to redo it by calling
+sysctl after each reboot.
+
  */
index 6adfdd5..2efb017 100644 (file)
@@ -3,7 +3,6 @@
 ! output sort
 
 $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar async/AsyncTest ${srcdir:=.}/examples/platform.xml ${srcdir:=.}/examples/async/asyncDeployment.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [  0.000000] (0:@) Ready to run MSG_MAIN
 > [  0.000000] (10:async.Slave@Robert) Receiving on 'slave_8'
 > [  0.000000] (11:async.Slave@Sirois) Receiving on 'slave_9'
 > [  0.000000] (12:async.Slave@Monique) Receiving on 'slave_10'
@@ -53,7 +52,5 @@ $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar async/AsyncTest ${sr
 > [ 25.000000] (1:async.Master@Jacquelin) Goodbye now!
 > [ 25.851463] (2:async.Forwarder@Jackson) I'm done. See you!
 > [ 26.357007] (3:async.Forwarder@Casavant) I'm done. See you!
-> [ 29.000728] (0:@) Done running MSG_MAIN
-> [ 29.000728] (0:@) MSG_main finished
-> [ 29.000728] (0:@) Clean java world
-> [ 29.000728] (0:@) Clean native world
+> [ 29.000728] (0:@) MSG_main finished; Cleaning up the simulation...
+> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up.
index 3919b49..1e170eb 100644 (file)
@@ -3,11 +3,8 @@
 ! output sort
 
 $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar bittorrent/Bittorrent ${srcdir:=.}/examples/platform.xml ${srcdir:=.}/examples/bittorrent/bittorrent.xml
-> [0.000000] [jmsg/INFO] Ready to run MSG_MAIN
-> [5000.832370] [jmsg/INFO] Done running MSG_MAIN
-> [5000.832370] [jmsg/INFO] MSG_main finished
-> [5000.832370] [jmsg/INFO] Clean java world
-> [5000.832370] [jmsg/INFO] Clean native world
+> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up.
+> [5000.832370] [jmsg/INFO] MSG_main finished; Cleaning up the simulation...
 > [Boivin:bittorrent.Peer:(2) 0.000000] [jmsg/INFO] Hi, I'm joining the network with id 2
 > [Boivin:bittorrent.Peer:(2) 5000.048882] [jmsg/INFO] Here is my current status: 1111111111
 > [Disney:bittorrent.Peer:(6) 0.000000] [jmsg/INFO] Hi, I'm joining the network with id 6
index 7f950b6..ba3f52e 100644 (file)
@@ -3,11 +3,8 @@
 ! output sort
 
 $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar chord/Chord ${srcdir:=.}/examples/platform.xml ${srcdir:=.}/examples/chord/chord.xml
-> [0.000000] [jmsg/INFO] Ready to run MSG_MAIN
-> [652.548539] [jmsg/INFO] Done running MSG_MAIN
-> [652.548539] [jmsg/INFO] MSG_main finished
-> [652.548539] [jmsg/INFO] Clean java world
-> [652.548539] [jmsg/INFO] Clean native world
+> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up.
+> [652.548539] [jmsg/INFO] MSG_main finished; Cleaning up the simulation...
 > [Boivin:chord.Node:(7) 0.000000] [jmsg/INFO] Joining the ring with id 8 knowing node 1
 > [Gatien:chord.Node:(1) 0.000000] [jmsg/INFO] Joining the ring with id 48 knowing node 1
 > [Geoff:chord.Node:(4) 0.000000] [jmsg/INFO] Joining the ring with id 32 knowing node 1
index 6cdd6ac..1edb24b 100644 (file)
@@ -37,6 +37,5 @@ public class Cloud {
                /* Execute the simulation */
                Msg.run();
                
-               Msg.clean();
     }
 }
\ No newline at end of file
index 2bf311f..bdb2c12 100644 (file)
@@ -3,7 +3,6 @@
 ! output sort
 
 $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar cloud/Cloud ${srcdir:=.}/examples/platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [  0.000000] (0:@) Ready to run MSG_MAIN
 > [  0.000000] (10:Slave 8@Jean_Yves) Receiving on slave_8
 > [  0.000000] (11:Slave 9@Fafard) Receiving on slave_9
 > [  0.000000] (1:Master@Jacquelin) Launched 10 VMs
@@ -60,6 +59,7 @@ $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar cloud/Cloud ${srcdir
 > [ 13.715289] (11:Slave 9@Fafard) Receiving on slave_9
 > [ 13.715289] (1:Master@Jacquelin) Enough. Let's resume everybody.
 > [ 13.715289] (1:Master@Jacquelin) Sleep long enough for everyone to be done with previous batch of work
+> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up.
 > [1000.000000] (12:Slave 10@Jacquelin) Receiving on slave_10
 > [1000.000000] (13:Slave 11@Intel) Receiving on slave_11
 > [1000.000000] (14:Slave 12@Provost) Receiving on slave_12
@@ -150,10 +150,7 @@ $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar cloud/Cloud ${srcdir
 > [1021.445768] (20:Slave 18@Provost) Received "Task_18". Processing it.
 > [1021.445768] (20:Slave 18@Provost) "Task_18" done 
 > [1021.445768] (20:Slave 18@Provost) Receiving on slave_18
-> [1023.430577] (0:@) Done running MSG_MAIN
-> [1023.430577] (0:@) MSG_main finished
-> [1023.430577] (0:@) Clean java world
-> [1023.430577] (0:@) Clean native world
+> [1023.430577] (0:@) MSG_main finished; Cleaning up the simulation...
 > [1023.430577] (1:Master@Jacquelin) Let's shut down the simulation and kill everyone.
 > [1023.430577] (1:Master@Jacquelin) Master done.
 > [1023.430577] (21:Slave 19@Provost) Received "Task_19". Processing it.
index 881c794..c7bf972 100644 (file)
@@ -3,11 +3,8 @@
 ! output sort
 
 $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar commTime/CommTimeTest ${srcdir:=.}/examples/platform.xml ${srcdir:=.}/examples/commTime/commTimeDeployment.xml
-> [0.000000] [jmsg/INFO] Ready to run MSG_MAIN
-> [7016.935689] [jmsg/INFO] Done running MSG_MAIN
-> [7016.935689] [jmsg/INFO] MSG_main finished
-> [7016.935689] [jmsg/INFO] Clean java world
-> [7016.935689] [jmsg/INFO] Clean native world
+> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up.
+> [7016.935689] [jmsg/INFO] MSG_main finished; Cleaning up the simulation...
 > [Bellemarre:commTime.Slave:(15) 0.000000] [jmsg/INFO] Receiving on 'slave_13'
 > [Bellemarre:commTime.Slave:(15) 7006.824050] [jmsg/INFO] Received Finalize. I'm done. See you!
 > [Boucherville:commTime.Slave:(18) 0.000000] [jmsg/INFO] Receiving on 'slave_16'
index 8df30c6..7396956 100644 (file)
@@ -3,11 +3,8 @@
 ! output sort
 
 $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar kademlia/Kademlia ${srcdir:=.}/examples/platform.xml ${srcdir:=.}/examples/kademlia/kademlia.xml
-> [0.000000] [jmsg/INFO] Ready to run MSG_MAIN
-> [900.000000] [jmsg/INFO] Done running MSG_MAIN
-> [900.000000] [jmsg/INFO] MSG_main finished
-> [900.000000] [jmsg/INFO] Clean java world
-> [900.000000] [jmsg/INFO] Clean native world
+> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up.
+> [900.000000] [jmsg/INFO] MSG_main finished; Cleaning up the simulation...
 > [Boivin:kademlia.Node:(2) 0.000000] [jmsg/INFO] Hi, I'm going to join the network with the id 1!
 > [Boivin:kademlia.Node:(2) 900.000000] [jmsg/INFO] 8/8 FIND_NODE have succedded.
 > [Jacquelin:kademlia.Node:(1) 0.000000] [jmsg/INFO] Hi, I'm going to create the network with the id 0!
index c9ba244..dfcc347 100644 (file)
@@ -3,11 +3,8 @@
 ! output sort
 
 $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar master_slave_bypass/MsBypass ${srcdir:=.}/examples/master_slave_bypass/platform.xml
-> [0.000000] [jmsg/INFO] Ready to run MSG_MAIN
-> [0.013010] [jmsg/INFO] Done running MSG_MAIN
-> [0.013010] [jmsg/INFO] MSG_main finished
-> [0.013010] [jmsg/INFO] Clean java world
-> [0.013010] [jmsg/INFO] Clean native world
+> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up.
+> [0.013010] [jmsg/INFO] MSG_main finished; Cleaning up the simulation...
 > [alice:process2:(2) 0.000000] [jmsg/INFO] Slave Hello!
 > [alice:process2:(2) 0.000000] [jmsg/INFO] Send finalize!
 > [bob:process1:(1) 0.000000] [jmsg/INFO] Master Hello!
index 6ae6f73..2c7179a 100644 (file)
@@ -3,11 +3,8 @@
 ! output sort
 
 $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar master_slave_kill/MsKill ${srcdir:=.}/examples/master_slave_kill/platform.xml
-> [0.000000] [jmsg/INFO] Ready to run MSG_MAIN
-> [0.013010] [jmsg/INFO] Done running MSG_MAIN
-> [0.013010] [jmsg/INFO] MSG_main finished
-> [0.013010] [jmsg/INFO] Clean java world
-> [0.013010] [jmsg/INFO] Clean native world
+> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up.
+> [0.013010] [jmsg/INFO] MSG_main finished; Cleaning up the simulation...
 > [alice:slave:(2) 0.000000] [jmsg/INFO] Slave Hello!
 > [alice:slave:(2) 0.000000] [jmsg/INFO] Send Mail1!
 > [bob:master:(1) 0.000000] [jmsg/INFO] Master Hello!
index b13ffaf..243f4c4 100644 (file)
@@ -3,7 +3,6 @@
 ! output sort
 
 $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar masterslave/Masterslave ${srcdir:=.}/examples/platform.xml ${srcdir:=.}/examples/masterslave/masterslaveDeployment.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [  0.000000] (0:@) Ready to run MSG_MAIN
 > [  0.000000] (1:masterslave.Master@Jacquelin) Hello! Got 7 slaves and 5 tasks to process
 > [  0.000000] (2:masterslave.Forwarder@Jackson) Receiving on 'slave_0'
 > [  0.000000] (3:masterslave.Forwarder@Casavant) Receiving on 'slave_1'
@@ -27,9 +26,7 @@ $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar masterslave/Mastersl
 > [ 13.977892] (5:masterslave.Slave@Bousquet) Received Finalize. I'm done. See you!
 > [ 15.421578] (6:masterslave.Slave@Soucy) Received Finalize. I'm done. See you!
 > [ 16.278886] (7:masterslave.Slave@Kuenning) Received Finalize. I'm done. See you!
-> [ 17.252217] (0:@) Done running MSG_MAIN
-> [ 17.252217] (0:@) MSG_main finished
-> [ 17.252217] (0:@) Clean java world
-> [ 17.252217] (0:@) Clean native world
+> [ 17.252217] (0:@) MSG_main finished; Cleaning up the simulation...
 > [ 17.252217] (1:masterslave.Master@Jacquelin) Goodbye now!
 > [ 17.252217] (8:masterslave.Slave@Browne) Received Finalize. I'm done. See you!
+> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up.
index 869acc5..e40cb50 100644 (file)
@@ -3,16 +3,13 @@
 ! output sort
 
 $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar migration/Migration ${srcdir:=.}/examples/platform.xml ${srcdir:=.}/examples/migration/migrationDeployment.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [  0.000000] (0:@) Ready to run MSG_MAIN
 > [  0.000000] (1:migration.Emigrant@Jacquelin) I'll look for a new job on another machine where the grass is greener.
 > [  0.000000] (1:migration.Emigrant@Boivin) Yeah, found something to do
 > [  1.000000] (2:migration.Policeman@Boivin) Wait a bit before migrating the emigrant.
 > [  3.000000] (1:migration.Emigrant@Boivin) Moving back to home after work
-> [  7.000000] (0:@) Done running MSG_MAIN
-> [  7.000000] (0:@) MSG_main finished
-> [  7.000000] (0:@) Clean java world
-> [  7.000000] (0:@) Clean native world
+> [  7.000000] (0:@) MSG_main finished; Cleaning up the simulation...
 > [  7.000000] (1:migration.Emigrant@Jacquelin) I've been moved on this new host:Jacquelin
 > [  7.000000] (1:migration.Emigrant@Jacquelin) Uh, nothing to do here. Stopping now
 > [  7.000000] (2:migration.Policeman@Boivin) I moved the emigrant
+> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up.
 
index e4aaa55..a8ca174 100644 (file)
@@ -3,11 +3,8 @@
 ! output sort
 
 $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar mutualExclusion/centralized/MutexCentral ${srcdir:=.}/examples/mutualExclusion/ring3.xml ${srcdir:=.}/examples/mutualExclusion/centralized/mutex_centralized_deployment.xml
-> [0.000000] [jmsg/INFO] Ready to run MSG_MAIN
-> [0.007806] [jmsg/INFO] Done running MSG_MAIN
-> [0.007806] [jmsg/INFO] MSG_main finished
-> [0.007806] [jmsg/INFO] Clean java world
-> [0.007806] [jmsg/INFO] Clean native world
+> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up.
+> [0.007806] [jmsg/INFO] MSG_main finished; Cleaning up the simulation...
 > [Host 0:mutualExclusion.centralized.Coordinator:(1) 0.001301] [jmsg/INFO] Got a request from mutualExclusion.centralized.Node. Queue empty: grant it
 > [Host 0:mutualExclusion.centralized.Coordinator:(1) 0.003903] [jmsg/INFO] Got a request from mutualExclusion.centralized.Node. Queue empty: grant it
 > [Host 0:mutualExclusion.centralized.Coordinator:(1) 0.007806] [jmsg/INFO] we should shutdown the simulation now
index 0f58fdd..cd4a7bf 100644 (file)
@@ -3,11 +3,8 @@
 ! output sort
 
 $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar pingPong/PingPongTest ${srcdir:=.}/examples/platform.xml ${srcdir:=.}/examples/pingPong/pingPongDeployment.xml
-> [0.000000] [jmsg/INFO] Ready to run MSG_MAIN
-> [1.048890] [jmsg/INFO] Done running MSG_MAIN
-> [1.048890] [jmsg/INFO] MSG_main finished
-> [1.048890] [jmsg/INFO] Clean java world
-> [1.048890] [jmsg/INFO] Clean native world
+> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up.
+> [1.048890] [jmsg/INFO] MSG_main finished; Cleaning up the simulation...
 > [Boivin:pingPong.Receiver:(2) 0.000000] [jmsg/INFO] hello!
 > [Boivin:pingPong.Receiver:(2) 0.000000] [jmsg/INFO] try to get a task
 > [Boivin:pingPong.Receiver:(2) 1.048890] [jmsg/INFO] Got at time 1.0488895059341703
index 9501626..f7ff99b 100644 (file)
@@ -3,13 +3,9 @@
 ! output sort
 
 $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar priority/Priority ${srcdir:=.}/examples/platform.xml ${srcdir:=.}/examples/priority/priorityDeployment.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [  0.000000] (0:@) Ready to run MSG_MAIN
 > [  0.000000] (1:priority.Test@Fafard) Hello! Running a task of size 7.6296E7 with priority 1.0
 > [  0.000000] (2:priority.Test@Fafard) Hello! Running a task of size 7.6296E7 with priority 2.0
 > [  0.833332] (2:priority.Test@Fafard) Goodbye now!
-> [  1.111109] (0:@) Done running MSG_MAIN
-> [  1.111109] (0:@) MSG_main finished
-> [  1.111109] (0:@) Clean java world
-> [  1.111109] (0:@) Clean native world
+> [  1.111109] (0:@) MSG_main finished; Cleaning up the simulation...
 > [  1.111109] (1:priority.Test@Fafard) Goodbye now!
-
+> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up.
index 364d621..edbe382 100644 (file)
@@ -1,6 +1,6 @@
 #! ./tesh
 $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar startKillTime/StartKillTime ${srcdir:=.}/examples/platform.xml ${srcdir:=.}/examples/startKillTime/deployment_start_kill.xml
-> [0.000000] [jmsg/INFO] Ready to run MSG_MAIN
+> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up.
 > [Jacquelin:startKillTime.Master:(1) 0.000000] [jmsg/INFO] Hello!
 > [Boivin:startKillTime.Slave:(2) 1.000000] [jmsg/INFO] Hello!
 > [Jean_Yves:startKillTime.Slave:(3) 2.000000] [jmsg/INFO] Hello!
@@ -8,7 +8,4 @@ $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar startKillTime/StartK
 > [Geoff:startKillTime.Slave:(5) 4.000000] [jmsg/INFO] Hello!
 > [Disney:startKillTime.Slave:(6) 5.000000] [jmsg/INFO] Hello!
 > [Jacquelin:startKillTime.Master:(1) 10.000000] [jmsg/INFO] OK, goodbye now.
-> [10.000000] [jmsg/INFO] Done running MSG_MAIN
-> [10.000000] [jmsg/INFO] MSG_main finished
-> [10.000000] [jmsg/INFO] Clean java world
-> [10.000000] [jmsg/INFO] Clean native world
+> [10.000000] [jmsg/INFO] MSG_main finished; Cleaning up the simulation...
index 323fb6a..c6ec5f7 100644 (file)
@@ -1,18 +1,14 @@
 #! ./tesh
 
 ! output sort
-
 $ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar suspend/Suspend ${srcdir:=.}/examples/platform.xml ${srcdir:=.}/examples/suspend/suspendDeployment.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [  0.000000] (0:@) Ready to run MSG_MAIN
 > [  0.000000] (1:suspend.DreamMaster@Jacquelin) Let's create a lazy guy.
 > [  0.000000] (1:suspend.DreamMaster@Jacquelin) Let's wait a little bit...
 > [  0.000000] (2:Lazy@Jacquelin) Nobody's watching me ? Let's go to sleep.
-> [ 10.000000] (0:@) Done running MSG_MAIN
-> [ 10.000000] (0:@) MSG_main finished
-> [ 10.000000] (0:@) Clean java world
-> [ 10.000000] (0:@) Clean native world
+> [ 10.000000] (0:@) MSG_main finished; Cleaning up the simulation...
 > [ 10.000000] (1:suspend.DreamMaster@Jacquelin) Let's wake the lazy guy up! >:) BOOOOOUUUHHH!!!!
 > [ 10.000000] (1:suspend.DreamMaster@Jacquelin) OK, goodbye now.
 > [ 10.000000] (2:Lazy@Jacquelin) Uuuh ? Did somebody call me ?
 > [ 10.000000] (2:Lazy@Jacquelin) Mmmh, goodbye now.
+> [0.000000] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up.
 
index 93b76f3..380b0a8 100644 (file)
@@ -42,6 +42,5 @@ public class TracingTest  {
 
                /*  execute the simulation. */
            Msg.run();
-                Msg.clean();
     }
 }
index 1098a2a..50b5660 100644 (file)
@@ -3,14 +3,11 @@
 ! 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] [jmsg/INFO] Using regular java threads. Coroutines could speed your simulation up.
 > [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
+> [4.474433] [jmsg/INFO] MSG_main finished; Cleaning up the simulation...
 > [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
index 66d264c..63e6d1e 100644 (file)
@@ -83,6 +83,7 @@ public class Comm {
         */
        public static native void nativeInit();
        static {
+               Msg.nativeInit();
                nativeInit();
        }       
 }
index fa42c6d..9076bcf 100644 (file)
@@ -61,6 +61,7 @@ public class File {
         */
        public static native void nativeInit();
        static {
+               Msg.nativeInit();
                nativeInit();
        }       
 }
\ No newline at end of file
index 136f4b2..4683f5d 100644 (file)
@@ -83,7 +83,6 @@ public class Host {
         * This static method returns the count of the installed hosts.
         *
         * @return                      The count of the installed hosts.
-        * FIXME: Not implemented.
         */ 
        public native static int getCount();
 
index 9edada6..d9333a2 100644 (file)
@@ -32,4 +32,7 @@ public class JniException extends RuntimeException {
         */ public JniException(String s) {
                 super(s);
         }
+       public JniException(String string, Exception e) {
+               super(string,e);
+       }
 }
index adb58c5..895fadf 100644 (file)
 
 package org.simgrid.msg;
 
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.File;
+
+
 public final class Msg {
        /* Statically load the library which contains all native functions used in here */
-       static {
+       static private boolean isNativeInited = false;
+       public static void nativeInit() {
+               if (isNativeInited)
+                       return;
                try {
+                       /* prefer the version on disk, if existing */
                        System.loadLibrary("SG_java");
-               } catch(UnsatisfiedLinkError e) {
+               } catch (UnsatisfiedLinkError e) {
+                       /* If not found, unpack the one bundled into the jar file and use it */
+                       loadLib("simgrid");
+                       loadLib("SG_java");
+               }
+               isNativeInited = true;
+       }
+       static {
+               nativeInit();
+       }
+       private static void loadLib (String name) {
+               String Path = "NATIVE/"+System.getProperty("os.name")+"/"+System.getProperty("os.arch")+"/";
+               String filename=name;
+               InputStream in = Msg.class.getClassLoader().getResourceAsStream(Path+filename);
+               
+               if (in == null) {
+                       filename = "lib"+name+".so";
+                       in = Msg.class.getClassLoader().getResourceAsStream(Path+filename);
+               } 
+               if (in == null) {
+                       filename = name+".dll";
+                       in = Msg.class.getClassLoader().getResourceAsStream(Path+filename);
+               }  
+               if (in == null) {
+                       filename = "lib"+name+".dll";
+                       in = Msg.class.getClassLoader().getResourceAsStream(Path+filename);
+               }  
+               if (in == null) {
+                       filename = "lib"+name+".dylib";
+                       in = Msg.class.getClassLoader().getResourceAsStream(Path+filename);
+               }  
+               if (in == null) {
+                       throw new RuntimeException("Cannot find library "+name+" in path "+Path+". Sorry, but this jar does not seem to be usable on your machine.");
+               }
+// Caching the file on disk: desactivated because it could fool the users              
+//             if (new File(filename).isFile()) {
+//                     // file was already unpacked -- use it directly
+//                     System.load(new File(".").getAbsolutePath()+File.separator+filename);
+//                     return;
+//             }
+               try {
+                       // We must write the lib onto the disk before loading it -- stupid operating systems
+                       File fileOut = new File(filename);
+//                     if (!new File(".").canWrite()) {
+//                             System.out.println("Cannot write in ."+File.separator+filename+"; unpacking the library into a temporary file instead");
+                               fileOut = File.createTempFile("simgrid-", ".tmp");
+                               // don't leak the file on disk, but remove it on JVM shutdown
+                               Runtime.getRuntime().addShutdownHook(new Thread(new FileCleaner(fileOut.getAbsolutePath())));
+//                     }
+//                     System.out.println("Unpacking SimGrid native library to " + fileOut.getAbsolutePath());
+                       OutputStream out = new FileOutputStream(fileOut);
+                       
+                       /* copy the library in position */  
+                       byte[] buffer = new byte[4096]; 
+                       int bytes_read; 
+                       while ((bytes_read = in.read(buffer)) != -1)     // Read until EOF
+                               out.write(buffer, 0, bytes_read); 
+                     
+                       /* close all file descriptors, and load that shit */
+                       in.close();
+                       out.close();
+                       System.load(fileOut.getAbsolutePath());
+               } catch (Exception 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 libraries to the current directory");
+                       System.err.println("This jar file does not seem to fit your system, sorry");
                        System.exit(1);
                }
+       }               
+       /* A hackish mechanism used to remove the file containing our library when the JVM shuts down */
+       private static class FileCleaner implements Runnable {
+               private String target;
+               public FileCleaner(String name) {
+                       target = name;
+               }
+        public void run() {
+            try {
+                new File(target).delete();
+            } catch(Exception e) {
+                System.out.println("Unable to clean temporary file "+target+" during shutdown.");
+                e.printStackTrace();
+            }
+        }    
        }
+
     /** Retrieve the simulation time
      * @return
      */
@@ -84,18 +171,9 @@ public final class Msg {
         */
        public final static native void run() ;
        
-       /**
-        * Cleanup the MSG simulation.
-        * 
-        * This function is only useful if you want to chain the simulations within 
-        * the same environment. But actually, it's not sure at all that cleaning the 
-        * JVM is faster than restarting a new one, so it's probable that using this 
-        * function is not a brilliant idea. Do so at own risk.
-        *      
-        * @see                    MSG_clean
-        */
-       public final static native void clean();
-       
+       /** This function is useless nowadays, just stop calling it. */
+       @Deprecated
+       public final static void clean(){}
 
        /**
         * The native implemented method to create the environment of the simulation.
index 7032b6e..cb16ffb 100644 (file)
@@ -31,6 +31,7 @@ public class Mutex {
         */
        public static native void nativeInit();
        static {
+               Msg.nativeInit();
                nativeInit();
        }       
 }
index e8ed072..edde2bf 100644 (file)
 package org.simgrid.msg;
  
 import java.util.Arrays;
-import java.util.Hashtable;
 import java.util.Vector;
-import java.lang.Runnable;
-import java.util.concurrent.Semaphore;
 
 /**
  * A process may be defined as a code, with some private data, executing 
@@ -404,6 +401,14 @@ public abstract class Process implements Runnable {
         */
        public static native void nativeInit();
        static {
+               Msg.nativeInit();
                nativeInit();
        }
+       /**
+        * This static method returns the current amount of processes running
+        *
+        * @return                      The count of the running processes
+        */ 
+       public native static int getCount();
+
 }
index c9f5471..58b9c9e 100644 (file)
@@ -113,6 +113,7 @@ public class RngStream {
         */
        public static native void nativeInit();
        static {
+               Msg.nativeInit();
                nativeInit();
        }
 }
\ No newline at end of file
index 84eaf88..a81e8fc 100644 (file)
@@ -277,6 +277,7 @@ public class Task {
         */
        public static native void nativeInit();
        static {
+               Msg.nativeInit();
                nativeInit();
        }
 }
index ede59a5..7943ed4 100644 (file)
  */
 package org.simgrid.trace;
 
+import org.simgrid.msg.Msg;
+
 public final class Trace {
        /* Statically load the library which contains all native functions used in here */
        static {
+               Msg.nativeInit();
                try {
                        System.loadLibrary("SG_java_tracing");
                } catch(UnsatisfiedLinkError e) {
index 09bdd55..41d7f36 100644 (file)
@@ -89,11 +89,11 @@ Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs)
   (*env)->GetJavaVM(env, &__java_vm);
 
   if ((*env)->FindClass(env, "java/dyn/Coroutine")) {
-       XBT_VERB("Using Coroutines");
+       XBT_INFO("Using Coroutines. Your simulation is on steroid.");
        smx_factory_initializer_to_use = SIMIX_ctx_cojava_factory_init;
   }
   else {
-       XBT_VERB("Using java threads");
+       XBT_INFO("Using regular java threads. Coroutines could speed your simulation up.");
        smx_factory_initializer_to_use = SIMIX_ctx_java_factory_init;
   }
   jthrowable exc = (*env)->ExceptionOccurred(env);
@@ -135,16 +135,14 @@ JNIEXPORT void JNICALL
   jobject jhost;
 
   /* Run everything */
-  XBT_INFO("Ready to run MSG_MAIN");
+  XBT_DEBUG("Ready to run MSG_MAIN");
   rv = MSG_main();
-  XBT_INFO("Done running MSG_MAIN");
+  XBT_DEBUG("Done running MSG_MAIN");
   jxbt_check_res("MSG_main()", rv, MSG_OK,
                  bprintf
                  ("unexpected error : MSG_main() failed .. please report this bug "));
 
-  XBT_INFO("MSG_main finished");
-
-  XBT_INFO("Clean java world");
+  XBT_INFO("MSG_main finished; Cleaning up the simulation...");
   /* Cleanup java hosts */
   hosts = MSG_hosts_as_dynar();
   for (index = 0; index < xbt_dynar_length(hosts) - 1; index++) {
@@ -154,16 +152,6 @@ JNIEXPORT void JNICALL
 
   }
   xbt_dynar_free(&hosts);
-  XBT_INFO("Clean native world");
-}
-JNIEXPORT void JNICALL
-    JNICALL Java_org_simgrid_msg_Msg_clean(JNIEnv * env, jclass cls)
-{
-  /* cleanup native stuff. Calling it is ... useless since leaking memory at the end of the simulation is a non-issue */
-  msg_error_t rv = MSG_OK != MSG_clean();
-  jxbt_check_res("MSG_clean()", rv, MSG_OK,
-                 bprintf
-                 ("unexpected error : MSG_clean() failed .. please report this bug "));
 }
 
 JNIEXPORT void JNICALL
index e614876..73e9ad9 100644 (file)
@@ -31,12 +31,6 @@ JNIEXPORT jdouble JNICALL Java_org_simgrid_msg_Msg_getClock(JNIEnv *, jclass);
  */
 JNIEXPORT void JNICALL
     JNICALL Java_org_simgrid_msg_Msg_run(JNIEnv * env, jclass cls);
-/**
- * Class               org_simgrid_msg_Msg
- * Method              clean
- */
-JNIEXPORT void JNICALL
-    JNICALL Java_org_simgrid_msg_Msg_clean(JNIEnv * env, jclass cls);
 
 JNIEXPORT void JNICALL
 Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs);
index 7773eeb..aaa73e7 100644 (file)
@@ -266,7 +266,8 @@ Java_org_simgrid_msg_Process_resume(JNIEnv * env,
   jxbt_check_res("MSG_process_resume()", rv, MSG_OK,
                  bprintf("unexpected error , please report this bug"));
 }
-JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_setAutoRestart
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_setAutoRestart
     (JNIEnv *env, jobject jprocess, jboolean jauto_restart) {
   msg_process_t process = jprocess_to_native_process(jprocess, env);
   xbt_ex_t e;
@@ -285,7 +286,8 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_setAutoRestart
     xbt_ex_free(e);
   }
 }
-JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_restart
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_restart
     (JNIEnv *env, jobject jprocess) {
   msg_process_t process = jprocess_to_native_process(jprocess, env);
   xbt_ex_t e;
@@ -318,7 +320,8 @@ Java_org_simgrid_msg_Process_isSuspended(JNIEnv * env,
   return (jboolean) MSG_process_is_suspended(process);
 }
 
-JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_sleep
+JNIEXPORT void JNICALL
+Java_org_simgrid_msg_Process_sleep
        (JNIEnv *env, jclass cls, jlong jmillis, jint jnanos) {
 
        double time =  jmillis / 1000 + jnanos / 1000;
@@ -398,3 +401,15 @@ Java_org_simgrid_msg_Process_setKillTime (JNIEnv *env , jobject jprocess, jdoubl
        msg_process_t process = jprocess_to_native_process(jprocess, env);
        MSG_process_set_kill_time(process, (double)jkilltime);
 }
+
+JNIEXPORT jint JNICALL
+Java_org_simgrid_msg_Process_getCount(JNIEnv * env, jclass cls) {
+       /* FIXME: the next test on SimGrid version is to ensure that this still compiles with SG 3.8 while the C function were added in SG 3.9 only.
+        * This kind of pimple becomes mandatory when you get so slow to release the java version that it begins evolving further after the C release date.
+        */
+#if SIMGRID_VERSION >= 30900
+  return (jint) MSG_process_get_number();
+#else
+  return (jint) -1;
+#endif
+}
index cfc7051..566a877 100644 (file)
@@ -261,4 +261,8 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_migrate
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_setKillTime
     (JNIEnv *, jobject, jdouble);
 
+JNIEXPORT jint JNICALL
+Java_org_simgrid_msg_Process_getCount(JNIEnv * env, jclass cls);
+
+
 #endif                          /* !MSG_JPROCESS_H */
index 42c655e..0c4c9f6 100644 (file)
@@ -255,7 +255,24 @@ static void smx_ctx_cojava_create_coroutine(smx_ctx_cojava_t context) {
   jclass coclass = (*env)->FindClass(env, "java/dyn/Coroutine");
   xbt_assert((coclass != NULL), "Can't find coroutine class ! :(");
   jobject jcoroutine = (*env)->NewObject(env, coclass, coroutine_init, context->jprocess);
-  xbt_assert((jcoroutine != NULL), "Can't create coroutine object.");
+  if (jcoroutine == NULL) {
+     FILE *conf= fopen("/proc/sys/vm/max_map_count","r");
+     if (conf) {
+       int limit=-1;
+       fscanf(conf,"%d",&limit);
+       fclose(conf);
+       if (limit!=-1 && SIMIX_process_count() > (limit - 100) /2)
+          xbt_die("Error while creating a new coroutine. "
+                  "This seem due to the the vm.max_map_count system limit that is only equal to %d while we already have %d coroutines. "
+                  "Please check the install documentation to see how to increase this limit", limit, SIMIX_process_count());
+       if (limit == -1)
+         xbt_die("Error while creating a new coroutine. "
+                 "This seems to be a non-linux system, disabling the automatic verification that the system limit on the amount of memory maps is high enough.");
+       xbt_die("Error while creating a new coroutine. ");
+     }
+     
+  }
+   
   jcoroutine = (*env)->NewGlobalRef(env, jcoroutine);
   context->jcoroutine = jcoroutine;
 }
index 9eed4af..02f6f7b 100644 (file)
@@ -80,7 +80,8 @@ smx_ctx_java_factory_create_context(xbt_main_func_t code, int argc,
     TRY {        
        context->thread = xbt_os_thread_create(NULL,smx_ctx_java_thread_run,context,NULL);
     } CATCH(e) {
-       RETHROWF("Impossible to create context #%d. You may want to switch to Java continuations to increase your limits (error: %s)",
+       RETHROWF("Failed to create context #%d. You may want to switch to Java coroutines to increase your limits (error: %s)."
+                "See the Install section of simgrid-java documentation (in doc/install.html) for more on coroutines.",
                        thread_amount);
     }
   }