From: alebre Date: Tue, 12 Jun 2012 20:44:02 +0000 (+0200) Subject: Merge branch 'master' of git://scm.gforge.inria.fr/simgrid/simgrid-java X-Git-Tag: v3_9_90~569^2~19^2~56 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/0fee76cf390f76e01411439d6f3590ac7dc158ff?hp=cd247d4e096b930f7f41eab3bfc9683adfccb39c Merge branch 'master' of git://scm.gforge.inria.fr/simgrid/simgrid-java Conflicts: CMakeLists.txt ChangeLog --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d64f21836..8d9e3bfe5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,6 +72,8 @@ include(FindJavaSG.cmake) # Declare our package content # ############################### set(JMSG_C_SRC + src/smx_context_cojava.h + src/smx_context_cojava.c src/smx_context_java.h src/smx_context_java.c src/jxbt_utilities.c @@ -80,16 +82,18 @@ set(JMSG_C_SRC src/jmsg.h src/jmsg_comm.c src/jmsg_comm.h + src/jmsg_file.c + src/jmsg_file.h src/jmsg_host.c src/jmsg_host.h src/jmsg_process.c src/jmsg_process.h - src/jmsg_task.c - src/jmsg_task.h - src/jmsg_synchro.c - src/jmsg_synchro.h src/jmsg_rngstream.c src/jmsg_rngstream.h + src/jmsg_synchro.c + src/jmsg_synchro.h + src/jmsg_task.c + src/jmsg_task.h ) set(JTRACE_C_SRC @@ -101,6 +105,7 @@ set(JMSG_JAVA_SRC org/simgrid/msg/Host.java org/simgrid/msg/HostFailureException.java org/simgrid/msg/HostNotFoundException.java + org/simgrid/msg/File.java org/simgrid/msg/JniException.java org/simgrid/msg/Msg.java org/simgrid/msg/MsgException.java @@ -121,6 +126,11 @@ set(JTRACE_JAVA_SRC ) set(JAVA_EXAMPLES + examples/async/AsyncTest.java + examples/async/FinalizeTask.java + examples/async/Forwarder.java + examples/async/Master.java + examples/async/Slave.java examples/bittorrent/Bittorrent.java examples/bittorrent/Common.java examples/bittorrent/Connection.java @@ -136,25 +146,17 @@ set(JAVA_EXAMPLES examples/chord/FindSuccessorTask.java examples/chord/GetPredecessorAnswerTask.java examples/chord/NotifyTask.java - examples/mutualExclusion/centralized/MutexCentral.java - examples/mutualExclusion/centralized/GrantTask.java - examples/mutualExclusion/centralized/Coordinator.java - examples/mutualExclusion/centralized/ReleaseTask.java - examples/mutualExclusion/centralized/Node.java - examples/mutualExclusion/centralized/RequestTask.java - examples/basic/FinalizeTask.java - examples/basic/Forwarder.java - examples/basic/Master.java - examples/basic/BasicTest.java - examples/basic/Slave.java examples/commTime/FinalizeTask.java examples/commTime/Master.java examples/commTime/Slave.java examples/commTime/CommTimeTest.java - examples/pingPong/PingPongTask.java - examples/pingPong/Sender.java - examples/pingPong/Receiver.java - examples/pingPong/PingPongTest.java + examples/io/IO.java + examples/io/Node.java + examples/masterslave/FinalizeTask.java + examples/masterslave/Forwarder.java + examples/masterslave/Master.java + examples/masterslave/Masterslave.java + examples/masterslave/Slave.java examples/master_slave_bypass/Master.java examples/master_slave_bypass/MsBypass.java examples/master_slave_bypass/Slave.java @@ -163,15 +165,26 @@ set(JAVA_EXAMPLES examples/master_slave_kill/MsKill.java examples/master_slave_kill/Slave.java examples/master_slave_kill/FinalizeTask.java - examples/async/AsyncTest.java - examples/async/FinalizeTask.java - examples/async/Forwarder.java - examples/async/Master.java - examples/async/Slave.java - examples/startKillTime/Slave.java + examples/migration/Emigrant.java + examples/migration/Migration.java + examples/migration/Policeman.java + examples/mutualExclusion/centralized/MutexCentral.java + examples/mutualExclusion/centralized/GrantTask.java + examples/mutualExclusion/centralized/Coordinator.java + examples/mutualExclusion/centralized/ReleaseTask.java + examples/mutualExclusion/centralized/Node.java + examples/mutualExclusion/centralized/RequestTask.java + examples/pingPong/PingPongTask.java + examples/pingPong/Sender.java + examples/pingPong/Receiver.java + examples/pingPong/PingPongTest.java examples/startKillTime/Master.java + examples/startKillTime/Slave.java examples/startKillTime/StartKillTime.java examples/tracing/PingPongTask.java + examples/suspend/DreamMaster.java + examples/suspend/LazyGuy.java + examples/suspend/Suspend.java examples/tracing/Sender.java examples/tracing/Receiver.java examples/tracing/TracingTest.java @@ -185,18 +198,18 @@ ${CMAKE_HOME_DIRECTORY}/FindSimGrid.cmake ) set(XML_FILES - examples/commTime/commTimeDeployment.xml - examples/mutualExclusion/ring3.xml - examples/mutualExclusion/centralized/mutex_centralized_deployment.xml examples/platform.xml - examples/pingPong/pingPongDeployment.xml - examples/basic/basicDeployment.xml - examples/basic/deploy.xml - examples/master_slave_bypass/platform.xml - examples/master_slave_kill/platform.xml examples/async/asyncDeployment.xml examples/tracing/tracingPingPongDeployment.xml examples/bittorrent/bittorrent.xml + examples/commTime/commTimeDeployment.xml + examples/masterslave/masterslaveDeployment.xml + examples/masterslave/deploy.xml + examples/master_slave_bypass/platform.xml + examples/master_slave_kill/platform.xml + examples/mutualExclusion/ring3.xml + examples/mutualExclusion/centralized/mutex_centralized_deployment.xml + examples/pingPong/pingPongDeployment.xml ) set(source_to_pack @@ -299,17 +312,23 @@ add_custom_command( COMMENT "Build examples for java" OUTPUT ${JAVA_EXAMPLES_CLASS} DEPENDS ${JAVA_EXAMPLES} - COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/basic/*.java - COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/async/*.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/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/mutualExclusion/centralized/*.java + COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/async/*.java + 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/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 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/bittorrent/*.java + COMMAND ${JAVA_COMPILE} -d ${CMAKE_HOME_DIRECTORY}/examples -cp ${CMAKE_HOME_DIRECTORY}/simgrid.jar ${CMAKE_HOME_DIRECTORY}/examples/suspend/*.java + ) add_custom_target(simgrid_java_examples ALL @@ -333,18 +352,22 @@ INCLUDE(CTest) ENABLE_TESTING() ADD_TEST(async ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/async/async.tesh) -ADD_TEST(basic ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/basic/basic.tesh) -ADD_TEST(bittorrent ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/bittorrent/bittorrent.tesh) -ADD_TEST(chord ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/chord/chord.tesh) -ADD_TEST(pingPong ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/pingPong/pingpong.tesh) -ADD_TEST(CommTime ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/commTime/commtime.tesh) -ADD_TEST(mutualExclusion ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/mutualExclusion/mutualexclusion.tesh) +ADD_TEST(bittorrent ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/bittorrent/bittorrent.tesh) ADD_TEST(bypass ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/master_slave_bypass/bypass.tesh) +ADD_TEST(commTime ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/commTime/commtime.tesh) +ADD_TEST(chord ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/chord/chord.tesh) ADD_TEST(kill ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/master_slave_kill/kill.tesh) +ADD_TEST(masterslave ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/masterslave/masterslave.tesh) +ADD_TEST(migration ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/migration/migration.tesh) +ADD_TEST(mutualExclusion ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/mutualExclusion/mutualexclusion.tesh) +ADD_TEST(pingPong ${TESH_BIN_PATH} ${TESH_OPTION} --setenv srcdir=${CMAKE_HOME_DIRECTORY} ${CMAKE_HOME_DIRECTORY}/examples/pingPong/pingpong.tesh) +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 basic bittorrent chord async pingPong CommTime mutualExclusion bypass kill startKillTime tracing) +#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 tracing) ########################################## # Set the DYLD_LIBRARY_PATH for mac # diff --git a/ChangeLog b/ChangeLog index 9f4e141880..7f6ac28baa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,21 +6,38 @@ SimGrid-java (3.8) unstable; urgency=low few of thems are really implemented at the JNI level (see ./src/jtrace.c for further information). -SimGrid-java (3.6.1) unstable; urgency=low - - * Introduce msg.simgrid.Mutex, exporting simgrid mutex to Java. +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 + * Make Process.kill(process) an instance method, not a static one + * User processes are not java.lang.Thread subclasses. + This breaks the compatibility (sorry), but previous API was + brain-dead, making it impossible to have non-trivial + initializations in the process constructor. + * Require a full constructor per Process sub-class. + Kinda breaks the compatibility (sorry), but this allows a much more + efficient way to launch the processes at simulation startup. * Do not embeed our version of semaphores, java 1.5 can be considered as sufficiently prevalent for us to not dupplicate its features. - * Make Process.kill(process) an instance method, not a static one - * Fix a bug around Process.kill() - * Add the asynchronous API to the bindings. - * Add "sleep" in Process with Thread-like syntax/use. - * Change the way the Process are created in ApplicationHandler: a full -constructor is now needed for your child classes. - * Change the way Process are created: Process are no longer a Thread subclass. - -- $date Da SimGrid team + * Lot of bug fixes + + Extend the API: + * Add examples for almost every part of the API + We spotted and fixed a lot of bugs in the process + + * New module: asynchronous communication API + * New function: Process.sleep() + It takes milliseconds as argument, just as java.lang.Thread.sleep() + * New module: org.simgrid.msg.Mutex (SimGrid mutexes) + * New module: org.simgrid.msg.RngStream (RngStreams random generators) -SimGrid-java (3.6) unstable; urgency=low + -- 2012-06-12 Da SimGrid team + +SimGrid-java (1.0 (3.6) unstable; urgency=low * Initial release. * Split of every thing from simgrid v3.5 into a separate package. diff --git a/GenerateDoc.cmake b/GenerateDoc.cmake index d8c9199f67..bcd7a7d4c8 100644 --- a/GenerateDoc.cmake +++ b/GenerateDoc.cmake @@ -61,6 +61,7 @@ add_dependencies(pdf simgrid_documentation) add_custom_target(sync-gforge-doc COMMAND chmod g+rw -R doc/ COMMAND chmod a+rX -R doc/ +COMMAND ssh scm.gforge.inria.fr mkdir /home/groups/simgrid/htdocs/simgrid-java/${SIMGRID_JAVA_VERSION_MAJOR}.${SIMGRID_JAVA_VERSION_MINOR} || true COMMAND rsync --verbose --cvs-exclude --compress --delete --delete-excluded --rsh=ssh --ignore-times --recursive --links --perms --times --omit-dir-times doc/html/ scm.gforge.inria.fr:/home/groups/simgrid/htdocs/simgrid-java/${SIMGRID_JAVA_VERSION_MAJOR}.${SIMGRID_JAVA_VERSION_MINOR}/doc/ || true WORKING_DIRECTORY "${CMAKE_HOME_DIRECTORY}" diff --git a/examples/async/AsyncTest.java b/examples/async/AsyncTest.java index 1e14632da9..f8abd3367e 100644 --- a/examples/async/AsyncTest.java +++ b/examples/async/AsyncTest.java @@ -22,23 +22,16 @@ public class AsyncTest { /* initialize the MSG simulation. Must be done before anything else (even logging). */ Msg.init(args); - if(args.length == 0) { - Msg.createEnvironment("async_platform.xml"); - Msg.deployApplication("async_deployment.xml"); - - } else if (args.length < 2) { - - + if (args.length < 2) { Msg.info("Usage : Async platform_file deployment_file"); - Msg.info("example : Async async_platform.xml async_deployment.xml"); - System.exit(1); - } else { - - /* construct the platform and deploy the application */ - Msg.createEnvironment(args[0]); - Msg.deployApplication(args[1]); + Msg.info("example : Async basic_platform.xml basic_deployment.xml"); + System.exit(1); } + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + /* execute the simulation. */ Msg.run(); } diff --git a/examples/basic/BasicTest.java b/examples/basic/BasicTest.java deleted file mode 100644 index af6f35bffd..0000000000 --- a/examples/basic/BasicTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 basic; - -import org.simgrid.msg.Msg; -import org.simgrid.msg.NativeException; - -public class BasicTest { - - /* 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 == 0) { - Msg.createEnvironment("basic_platform.xml"); - Msg.deployApplication("basic_deployment.xml"); - - } else if (args.length < 2) { - - - Msg.info("Usage : Basic platform_file deployment_file"); - Msg.info("example : Basic basic_platform.xml basic_deployment.xml"); - System.exit(1); - } else { - - /* construct the platform and deploy the application */ - Msg.createEnvironment(args[0]); - Msg.deployApplication(args[1]); - } - - /* execute the simulation. */ - Msg.run(); - } -} diff --git a/examples/basic/basic.tesh b/examples/basic/basic.tesh deleted file mode 100644 index f05eba9c58..0000000000 --- a/examples/basic/basic.tesh +++ /dev/null @@ -1,35 +0,0 @@ -#! ./tesh - -! output sort - -$ java -cp .:${srcdir:=.}/examples:${srcdir:=.}/simgrid.jar basic/BasicTest ${srcdir:=.}/examples/platform.xml ${srcdir:=.}/examples/basic/basicDeployment.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n" -> [ 0.000000] (0:@) Ready to run MSG_MAIN -> [ 0.000000] (1:basic.Master@Jacquelin) Hello! Got 7 slaves and 5 tasks to process -> [ 0.000000] (2:basic.Forwarder@Jackson) Receiving on 'slave_0' -> [ 0.000000] (3:basic.Forwarder@Casavant) Receiving on 'slave_1' -> [ 0.851529] (2:basic.Forwarder@Jackson) Sending "Task_0" to "slave_7" -> [ 2.208640] (3:basic.Forwarder@Casavant) Sending "Task_1" to "slave_9" -> [ 2.720598] (11:basic.Slave@Sirois) Received "Task_1". Processing it. -> [ 3.554211] (9:basic.Slave@Stephen) Received "Task_0". Processing it. -> [ 5.252532] (4:basic.Slave@iRMX) Received "Task_2". Processing it. -> [ 6.267288] (5:basic.Slave@Bousquet) Received "Task_3". Processing it. -> [ 7.711085] (1:basic.Master@Jacquelin) All tasks have been dispatched. Let's tell everybody the computation is over. -> [ 7.711085] (6:basic.Slave@Soucy) Received "Task_4". Processing it. -> [ 8.562549] (2:basic.Forwarder@Jackson) Got a finalize task. Let's forward that we're done. -> [ 9.919556] (3:basic.Forwarder@Casavant) Got a finalize task. Let's forward that we're done. -> [ 10.431474] (11:basic.Slave@Sirois) Received Finalize. I'm done. See you! -> [ 11.265023] (9:basic.Slave@Stephen) Received Finalize. I'm done. See you! -> [ 11.318960] (12:basic.Slave@Monique) Received Finalize. I'm done. See you! -> [ 11.318960] (3:basic.Forwarder@Casavant) I'm done. See you! -> [ 12.963214] (4:basic.Slave@iRMX) Received Finalize. I'm done. See you! -> [ 13.908112] (10:basic.Slave@Robert) Received Finalize. I'm done. See you! -> [ 13.908112] (2:basic.Forwarder@Jackson) I'm done. See you! -> [ 13.977892] (5:basic.Slave@Bousquet) Received Finalize. I'm done. See you! -> [ 15.421578] (6:basic.Slave@Soucy) Received Finalize. I'm done. See you! -> [ 16.278886] (7:basic.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] (1:basic.Master@Jacquelin) Goodbye now! -> [ 17.252217] (8:basic.Slave@Browne) Received Finalize. I'm done. See you! \ No newline at end of file diff --git a/examples/basic/deploy.xml b/examples/basic/deploy.xml deleted file mode 100644 index f1351dca2d..0000000000 --- a/examples/basic/deploy.xml +++ /dev/null @@ -1,114 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/examples/io/IO.java b/examples/io/IO.java new file mode 100644 index 0000000000..6a6674fb8f --- /dev/null +++ b/examples/io/IO.java @@ -0,0 +1,36 @@ +/* + * 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 diff --git a/examples/io/Node.java b/examples/io/Node.java new file mode 100644 index 0000000000..5afc600bcc --- /dev/null +++ b/examples/io/Node.java @@ -0,0 +1,59 @@ +/* + * 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 diff --git a/examples/io/storage.xml b/examples/io/storage.xml new file mode 100644 index 0000000000..58fca8974e --- /dev/null +++ b/examples/io/storage.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/master_slave_bypass/platform.xml b/examples/master_slave_bypass/platform.xml index 310c6e65d2..776a31b11d 100644 --- a/examples/master_slave_bypass/platform.xml +++ b/examples/master_slave_bypass/platform.xml @@ -26,4 +26,4 @@ - \ No newline at end of file + diff --git a/examples/basic/FinalizeTask.java b/examples/masterslave/FinalizeTask.java similarity index 93% rename from examples/basic/FinalizeTask.java rename to examples/masterslave/FinalizeTask.java index 7034e4ca00..c95e455485 100644 --- a/examples/basic/FinalizeTask.java +++ b/examples/masterslave/FinalizeTask.java @@ -5,7 +5,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ -package basic; +package masterslave; import org.simgrid.msg.Task; public class FinalizeTask extends Task { @@ -13,4 +13,4 @@ public class FinalizeTask extends Task { super("finalize",0,0); } } - \ No newline at end of file + diff --git a/examples/basic/Forwarder.java b/examples/masterslave/Forwarder.java similarity index 98% rename from examples/basic/Forwarder.java rename to examples/masterslave/Forwarder.java index e8faf39e5e..0c285ee4d0 100644 --- a/examples/basic/Forwarder.java +++ b/examples/masterslave/Forwarder.java @@ -5,7 +5,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ -package basic; +package masterslave; import org.simgrid.msg.Host; import org.simgrid.msg.Msg; diff --git a/examples/basic/Master.java b/examples/masterslave/Master.java similarity index 98% rename from examples/basic/Master.java rename to examples/masterslave/Master.java index dfb4a9b475..9d582cf8be 100644 --- a/examples/basic/Master.java +++ b/examples/masterslave/Master.java @@ -7,7 +7,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ -package basic; +package masterslave; import org.simgrid.msg.Host; import org.simgrid.msg.Msg; import org.simgrid.msg.MsgException; diff --git a/examples/masterslave/Masterslave.java b/examples/masterslave/Masterslave.java new file mode 100644 index 0000000000..03acdc6b69 --- /dev/null +++ b/examples/masterslave/Masterslave.java @@ -0,0 +1,35 @@ +/* + * 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 masterslave; + +import org.simgrid.msg.Msg; +import org.simgrid.msg.NativeException; + +public class Masterslave { + + /* 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 : Masterslave platform_file deployment_file"); + Msg.info("example : Masterslave basic_platform.xml basic_deployment.xml"); + System.exit(1); + } + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + /* execute the simulation. */ + Msg.run(); + } +} diff --git a/examples/basic/README b/examples/masterslave/README similarity index 100% rename from examples/basic/README rename to examples/masterslave/README diff --git a/examples/basic/Slave.java b/examples/masterslave/Slave.java similarity index 98% rename from examples/basic/Slave.java rename to examples/masterslave/Slave.java index dc216a4d46..e72b76d30d 100644 --- a/examples/basic/Slave.java +++ b/examples/masterslave/Slave.java @@ -4,7 +4,7 @@ * 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 basic; +package masterslave; import org.simgrid.msg.Host; import org.simgrid.msg.HostFailureException; @@ -45,4 +45,4 @@ public class Slave extends Process { Msg.info("Received Finalize. I'm done. See you!"); } -} \ No newline at end of file +} diff --git a/examples/masterslave/deploy.xml b/examples/masterslave/deploy.xml new file mode 100644 index 0000000000..f72a8b9523 --- /dev/null +++ b/examples/masterslave/deploy.xml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + diff --git a/examples/masterslave/masterslave.tesh b/examples/masterslave/masterslave.tesh new file mode 100644 index 0000000000..b13ffaf143 --- /dev/null +++ b/examples/masterslave/masterslave.tesh @@ -0,0 +1,35 @@ +#! ./tesh + +! 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' +> [ 0.851529] (2:masterslave.Forwarder@Jackson) Sending "Task_0" to "slave_7" +> [ 2.208640] (3:masterslave.Forwarder@Casavant) Sending "Task_1" to "slave_9" +> [ 2.720598] (11:masterslave.Slave@Sirois) Received "Task_1". Processing it. +> [ 3.554211] (9:masterslave.Slave@Stephen) Received "Task_0". Processing it. +> [ 5.252532] (4:masterslave.Slave@iRMX) Received "Task_2". Processing it. +> [ 6.267288] (5:masterslave.Slave@Bousquet) Received "Task_3". Processing it. +> [ 7.711085] (1:masterslave.Master@Jacquelin) All tasks have been dispatched. Let's tell everybody the computation is over. +> [ 7.711085] (6:masterslave.Slave@Soucy) Received "Task_4". Processing it. +> [ 8.562549] (2:masterslave.Forwarder@Jackson) Got a finalize task. Let's forward that we're done. +> [ 9.919556] (3:masterslave.Forwarder@Casavant) Got a finalize task. Let's forward that we're done. +> [ 10.431474] (11:masterslave.Slave@Sirois) Received Finalize. I'm done. See you! +> [ 11.265023] (9:masterslave.Slave@Stephen) Received Finalize. I'm done. See you! +> [ 11.318960] (12:masterslave.Slave@Monique) Received Finalize. I'm done. See you! +> [ 11.318960] (3:masterslave.Forwarder@Casavant) I'm done. See you! +> [ 12.963214] (4:masterslave.Slave@iRMX) Received Finalize. I'm done. See you! +> [ 13.908112] (10:masterslave.Slave@Robert) Received Finalize. I'm done. See you! +> [ 13.908112] (2:masterslave.Forwarder@Jackson) I'm done. See you! +> [ 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] (1:masterslave.Master@Jacquelin) Goodbye now! +> [ 17.252217] (8:masterslave.Slave@Browne) Received Finalize. I'm done. See you! diff --git a/examples/basic/basicDeployment.xml b/examples/masterslave/masterslaveDeployment.xml similarity index 67% rename from examples/basic/basicDeployment.xml rename to examples/masterslave/masterslaveDeployment.xml index 7edfa6d0d0..6c01ac0120 100644 --- a/examples/basic/basicDeployment.xml +++ b/examples/masterslave/masterslaveDeployment.xml @@ -1,49 +1,49 @@ - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/examples/migration/Emigrant.java b/examples/migration/Emigrant.java new file mode 100644 index 0000000000..c87508125d --- /dev/null +++ b/examples/migration/Emigrant.java @@ -0,0 +1,42 @@ +/* + * 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 migration; + +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; + +public class Emigrant extends Process { + public Emigrant(Host host, String name, String[]args) { + super(host,name,args); + } + public void main(String[] args) throws MsgException { + Migration.mutex.acquire(); + + Msg.info("I'll look for a new job on another machine where the grass is greener."); + migrate(Host.getByName("Boivin")); + + Msg.info("Yeah, found something to do"); + Task task = new Task("job", 98095000, 0); + task.execute(); + waitFor(2); + + Msg.info("Moving back to home after work"); + migrate(Host.getByName("Jacquelin")); + migrate(Host.getByName("Boivin")); + waitFor(4); + + Migration.processToMigrate = this; + Migration.mutex.release(); + suspend(); + + Msg.info("I've been moved on this new host:" + getHost().getName()); + Msg.info("Uh, nothing to do here. Stopping now"); + } +} \ No newline at end of file diff --git a/examples/migration/Migration.java b/examples/migration/Migration.java new file mode 100644 index 0000000000..bcf17ab095 --- /dev/null +++ b/examples/migration/Migration.java @@ -0,0 +1,46 @@ +/* + * $Id$ + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * 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 migration; +import org.simgrid.msg.Msg; +import org.simgrid.msg.Mutex; +import org.simgrid.msg.NativeException; +import org.simgrid.msg.Process; +/** + * Demonstrates the use of Task.setPriority to change + * the computation priority of a task + */ +public class Migration { + public static Mutex mutex; + public static Process processToMigrate = null; + + /* 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 : Priority platform_file deployment_file"); + Msg.info("example : Priority ping_pong_platform.xml ping_pong_deployment.xml"); + System.exit(1); + } + /* Create the mutex */ + mutex = new Mutex(); + + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + + /* execute the simulation. */ + Msg.run(); + } +} diff --git a/examples/migration/Policeman.java b/examples/migration/Policeman.java new file mode 100644 index 0000000000..3e01db31c7 --- /dev/null +++ b/examples/migration/Policeman.java @@ -0,0 +1,32 @@ +/* + * 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 migration; + +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; + +public class Policeman extends Process { + public Policeman(Host host, String name, String[]args) { + super(host,name,args); + } + + @Override + public void main(String[] args) throws MsgException { + waitFor(1); + + Msg.info("Wait a bit before migrating the emigrant."); + + Migration.mutex.acquire(); + + Migration.processToMigrate.migrate(Host.getByName("Jacquelin")); + Msg.info("I moved the emigrant"); + Migration.processToMigrate.resume(); + } +} \ No newline at end of file diff --git a/examples/migration/migration.tesh b/examples/migration/migration.tesh new file mode 100644 index 0000000000..869acc592a --- /dev/null +++ b/examples/migration/migration.tesh @@ -0,0 +1,18 @@ +#! ./tesh + +! 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] (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 + diff --git a/examples/migration/migrationDeployment.xml b/examples/migration/migrationDeployment.xml new file mode 100644 index 0000000000..db7c6c0905 --- /dev/null +++ b/examples/migration/migrationDeployment.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/examples/priority/Priority.java b/examples/priority/Priority.java new file mode 100644 index 0000000000..e5bcfb75f2 --- /dev/null +++ b/examples/priority/Priority.java @@ -0,0 +1,40 @@ +/* + * $Id$ + * + * Copyright 2006,2007 Martin Quinson, Malek Cherier + * 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 priority; +import org.simgrid.msg.Msg; +import org.simgrid.msg.NativeException; +/** + * Demonstrates the use of Task.setPriority to change + * the computation priority of a task + */ +public class Priority { + + /* 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 : Priority platform_file deployment_file"); + Msg.info("example : Priority 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]); + + /* execute the simulation. */ + Msg.run(); + } +} diff --git a/examples/priority/Test.java b/examples/priority/Test.java new file mode 100644 index 0000000000..365e8dfd44 --- /dev/null +++ b/examples/priority/Test.java @@ -0,0 +1,34 @@ +/* + * 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 priority; +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; + +public class Test extends Process { + public Test(Host host, String name, String[]args) { + super(host,name,args); + } + public void main(String[] args) throws MsgException { + double computationAmount = 1.0; + double priority = 1.0; + + computationAmount = Double.valueOf(args[0]); + priority = Double.valueOf(args[1]); + + Msg.info("Hello! Running a task of size " + computationAmount + " with priority " + priority); + + Task task = new Task("Task", computationAmount, 0); + task.setPriority(priority); + + task.execute(); + + Msg.info("Goodbye now!"); + } +} diff --git a/examples/priority/priority.tesh b/examples/priority/priority.tesh new file mode 100644 index 0000000000..9501626281 --- /dev/null +++ b/examples/priority/priority.tesh @@ -0,0 +1,15 @@ +#! ./tesh + +! 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] (1:priority.Test@Fafard) Goodbye now! + diff --git a/examples/priority/priorityDeployment.xml b/examples/priority/priorityDeployment.xml new file mode 100644 index 0000000000..78c4958a37 --- /dev/null +++ b/examples/priority/priorityDeployment.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/examples/suspend/DreamMaster.java b/examples/suspend/DreamMaster.java new file mode 100644 index 0000000000..f3bb90d980 --- /dev/null +++ b/examples/suspend/DreamMaster.java @@ -0,0 +1,21 @@ +package suspend; + +import org.simgrid.msg.Host; +import org.simgrid.msg.Msg; +import org.simgrid.msg.Process; +import org.simgrid.msg.MsgException; +public class DreamMaster extends Process { + public DreamMaster(Host host, String name, String[]args) { + super(host,name,args); + } + public void main(String[] args) throws MsgException { + Msg.info("Let's create a lazy guy."); + Process lazyGuy = new LazyGuy(getHost(),"Lazy",null); + lazyGuy.start(); + Msg.info("Let's wait a little bit..."); + waitFor(10); + Msg.info("Let's wake the lazy guy up! >:) BOOOOOUUUHHH!!!!"); + lazyGuy.resume(); + Msg.info("OK, goodbye now."); + } +} \ No newline at end of file diff --git a/examples/suspend/LazyGuy.java b/examples/suspend/LazyGuy.java new file mode 100644 index 0000000000..09046368a4 --- /dev/null +++ b/examples/suspend/LazyGuy.java @@ -0,0 +1,17 @@ +package suspend; + +import org.simgrid.msg.Host; +import org.simgrid.msg.Msg; +import org.simgrid.msg.Process; +import org.simgrid.msg.MsgException; +public class LazyGuy extends Process { + public LazyGuy(Host host, String name, String[]args) { + super(host,name,args); + } + public void main(String[] args) throws MsgException { + Msg.info("Nobody's watching me ? Let's go to sleep."); + suspend(); + Msg.info("Uuuh ? Did somebody call me ?"); + Msg.info("Mmmh, goodbye now."); + } +} \ No newline at end of file diff --git a/examples/suspend/Suspend.java b/examples/suspend/Suspend.java new file mode 100644 index 0000000000..b628c307d7 --- /dev/null +++ b/examples/suspend/Suspend.java @@ -0,0 +1,21 @@ +package suspend; + +import org.simgrid.msg.Msg; + +public class Suspend { + public static void main(String[] args) { + /* initialize the MSG simulation. Must be done before anything else (even logging). */ + Msg.init(args); + if(args.length < 2) { + Msg.info("Usage : Suspend platform_file deployment_file"); + Msg.info("example : Suspend platform.xml deployment.xml"); + System.exit(1); + } + /* construct the platform and deploy the application */ + Msg.createEnvironment(args[0]); + Msg.deployApplication(args[1]); + + /* execute the simulation. */ + Msg.run(); + } +} diff --git a/examples/suspend/suspend.tesh b/examples/suspend/suspend.tesh new file mode 100644 index 0000000000..323fb6ad58 --- /dev/null +++ b/examples/suspend/suspend.tesh @@ -0,0 +1,18 @@ +#! ./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] (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. + diff --git a/examples/suspend/suspendDeployment.xml b/examples/suspend/suspendDeployment.xml new file mode 100644 index 0000000000..af3d363f68 --- /dev/null +++ b/examples/suspend/suspendDeployment.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/org/simgrid/msg/File.java b/org/simgrid/msg/File.java new file mode 100644 index 0000000000..0f85eb4fa9 --- /dev/null +++ b/org/simgrid/msg/File.java @@ -0,0 +1,66 @@ +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 diff --git a/org/simgrid/msg/HostFailureException.java b/org/simgrid/msg/HostFailureException.java index 083aa4a6d2..fb9bcf3b3b 100644 --- a/org/simgrid/msg/HostFailureException.java +++ b/org/simgrid/msg/HostFailureException.java @@ -12,7 +12,7 @@ package org.simgrid.msg; /** - * This exception is raised when The host on which you are running has just been rebooted. + * This exception is raised when the host on which you are running has just been rebooted. */ public class HostFailureException extends MsgException { private static final long serialVersionUID = 1L; diff --git a/org/simgrid/msg/Msg.java b/org/simgrid/msg/Msg.java index a4db8becd3..c2b9cd720f 100644 --- a/org/simgrid/msg/Msg.java +++ b/org/simgrid/msg/Msg.java @@ -24,28 +24,6 @@ public final class Msg { System.exit(1); } } - - /** Everything is right. Keep on going the way ! */ - public static final int SUCCESS = 0; - - /** Something must be not perfectly clean (but I may be paranoid freak...) */ - public static final int WARNING = 1; - - /** There has been a problem during your task transfer. - * Either the network is down or the remote host has been shutdown */ - public static final int TRANSFERT_FAILURE = 2; - - /** System shutdown. - * The host on which you are running has just been rebooted. - * Free your data structures and return now ! */ - public static final int HOST_FAILURE = 3; - - /** Canceled task. This task has been canceled by somebody ! */ - public static final int TASK_CANCELLLED = 4; - - /** You've done something wrong. You'd better look at it... */ - public static final int FATAL_ERROR = 5; - /** Retrieve the simulation time * @return */ diff --git a/org/simgrid/msg/Mutex.java b/org/simgrid/msg/Mutex.java index b88e4d2bb9..7032b6e3ad 100644 --- a/org/simgrid/msg/Mutex.java +++ b/org/simgrid/msg/Mutex.java @@ -1,8 +1,4 @@ -package org.simgrid.msg; -/** A mutex implemented on top of SimGrid synchronization mechanisms. - * You can use it exactly the same way that you use the mutexes, - * but to handle the interactions between the threads within the simulation. - * +/* * Copyright 2012 The SimGrid team. All right reserved. * * This program is free software; you can redistribute @@ -10,17 +6,23 @@ package org.simgrid.msg; * (GNU LGPL) which comes with this package. * */ +package org.simgrid.msg; +/** A mutex implemented on top of SimGrid synchronization mechanisms. + * You can use it exactly the same way that you use the mutexes, + * but to handle the interactions between the processes within the simulation. + * + */ public class Mutex { private long bind; // The C object -- don't touch it - public Mutex(int capa) { - init(capa); + public Mutex() { + init(); } protected void finalize() { exit(); } private native void exit(); - private native void init(int capacity); + private native void init(); public native void acquire(); public native void release(); diff --git a/org/simgrid/msg/Process.java b/org/simgrid/msg/Process.java index 82e6c4fe16..714a7a3a75 100644 --- a/org/simgrid/msg/Process.java +++ b/org/simgrid/msg/Process.java @@ -230,16 +230,31 @@ public abstract class Process implements Runnable { /** * Suspends the process by suspending the task on which it was * waiting for the completion. - * */ - public native void pause(); + public native void suspend(); + /** + * Suspends the process by suspending the task on which it was + * waiting for the completion. + * DEPRECATED: use suspend instead. + */ + @Deprecated + public void pause() { + suspend(); + } /** * Resumes a suspended process by resuming the task on which it was * waiting for the completion. - * - * + * DEPRECATED: use resume instead. */ - public native void restart(); + @Deprecated + public void restart() { + resume(); + } + /** + * Resumes a suspended process by resuming the task on which it was + * waiting for the completion. + */ + public native void resume(); /** * Tests if a process is suspended. * @@ -288,6 +303,12 @@ public abstract class Process implements Runnable { public int getPPID() { return ppid; } + /** + * Set the kill time of the process + * @param killTime the time when the process is killed + */ + public native void setKillTime(double killTime); + /** * This static method returns the currently running process. * @@ -302,7 +323,7 @@ public abstract class Process implements Runnable { * @param host The host where to migrate the process. * */ - public native static void migrate(Process process, Host host); + public native void migrate(Host host); /** * Makes the current process sleep until millis millisecondes have elapsed. * You should note that unlike "waitFor" which takes seconds, this method takes milliseconds. @@ -371,6 +392,7 @@ public abstract class Process implements Runnable { catch(ProcessKilledError pk) { } + exit(); } /** @@ -381,7 +403,7 @@ public abstract class Process implements Runnable { */ public abstract void main(String[]args) throws MsgException; - + public native void exit(); /** * Class initializer, to initialize various JNI stuff */ diff --git a/org/simgrid/msg/ProcessKilledError.java b/org/simgrid/msg/ProcessKilledError.java index 6cd1c4a458..56dcb872d6 100644 --- a/org/simgrid/msg/ProcessKilledError.java +++ b/org/simgrid/msg/ProcessKilledError.java @@ -1,7 +1,9 @@ package org.simgrid.msg; -/** This exception class is only used to interrupt the java user code - * when the process gets killed by an external event */ +/** This error class is only used to interrupt the java user code + * when the process gets killed by an external event. + * Don't catch it. + */ public class ProcessKilledError extends Error { private static final long serialVersionUID = 1L; diff --git a/org/simgrid/msg/RngStream.java b/org/simgrid/msg/RngStream.java index 4b9b734f6c..5f4a8bf3b0 100644 --- a/org/simgrid/msg/RngStream.java +++ b/org/simgrid/msg/RngStream.java @@ -76,7 +76,7 @@ public class RngStream { */ 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); @@ -91,14 +91,14 @@ public class RngStream { /** * Advances the state of the stream by k values, without modifying the states of other streams (as * in RngStream_SetSeed), nor the values of Bg and Ig associated with this stream. If e > 0, then - * k = 2e + c; if e < 0, then k = −2−e + c; and if e = 0, then k = c. Note: c is allowed to take - *negative values. We discourage the use of this procedure. + * k = 2e + c; if e < 0, then k = -2-e + c; and if e = 0, then k = c. Note: c is allowed to take + * negative values. We discourage the use of this procedure. */ public native void advanceState(int e, int g); /** * Returns a (pseudo)random number from the uniform distribution over the interval (0, 1), after advancing the state by one step. The returned number has 32 bits of precision - * in the sense that it is always a multiple of 1/(232 − 208), unless RngStream_IncreasedPrecis + * in the sense that it is always a multiple of 1/(232 - 208), unless RngStream_IncreasedPrecis * has been called for this stream. */ public native double randU01(); diff --git a/src/jmsg.c b/src/jmsg.c index aaf5b10819..92d5d979ca 100644 --- a/src/jmsg.c +++ b/src/jmsg.c @@ -12,6 +12,7 @@ #include #include "smx_context_java.h" +#include "smx_context_cojava.h" #include "jmsg_process.h" @@ -87,7 +88,18 @@ Java_org_simgrid_msg_Msg_init(JNIEnv * env, jclass cls, jobjectArray jargs) (*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"); @@ -231,7 +243,6 @@ static int create_jprocess(int argc, char *argv[]) { /* 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; diff --git a/src/jmsg_file.c b/src/jmsg_file.c new file mode 100644 index 0000000000..3695fb8379 --- /dev/null +++ b/src/jmsg_file.c @@ -0,0 +1,76 @@ +/* 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); + +} + diff --git a/src/jmsg_file.h b/src/jmsg_file.h new file mode 100644 index 0000000000..4202ea2ac9 --- /dev/null +++ b/src/jmsg_file.h @@ -0,0 +1,50 @@ +/* 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 +#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 diff --git a/src/jmsg_host.c b/src/jmsg_host.c index c01a13256e..9fae1d7433 100644 --- a/src/jmsg_host.c +++ b/src/jmsg_host.c @@ -56,7 +56,6 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Host_nativeInit(JNIEnv *env, jclass cls) { jclass class_Host = (*env)->FindClass(env, "org/simgrid/msg/Host"); jhost_method_Host_constructor = (*env)->GetMethodID(env, class_Host, "", "()V"); - //FIXME: Don't use jxbt_get_sfield directly, it is slower. jhost_field_Host_bind = jxbt_get_jfield(env,class_Host, "bind", "J"); jhost_field_Host_name = jxbt_get_jfield(env, class_Host, "name", "Ljava/lang/String;"); if (!class_Host || !jhost_field_Host_name || !jhost_method_Host_constructor || !jhost_field_Host_bind) { diff --git a/src/jmsg_process.c b/src/jmsg_process.c index 6b2284dfdc..dc3d26271b 100644 --- a/src/jmsg_process.c +++ b/src/jmsg_process.c @@ -11,9 +11,19 @@ #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; @@ -206,7 +216,7 @@ Java_org_simgrid_msg_Process_currentProcess(JNIEnv * env, jclass cls) } JNIEXPORT void JNICALL -Java_org_simgrid_msg_Process_pause(JNIEnv * env, +Java_org_simgrid_msg_Process_suspend(JNIEnv * env, jobject jprocess) { m_process_t process = jprocess_to_native_process(jprocess, env); @@ -224,7 +234,7 @@ Java_org_simgrid_msg_Process_pause(JNIEnv * env, } JNIEXPORT void JNICALL -Java_org_simgrid_msg_Process_restart(JNIEnv * env, +Java_org_simgrid_msg_Process_resume(JNIEnv * env, jobject jprocess) { m_process_t process = jprocess_to_native_process(jprocess, env); @@ -325,3 +335,8 @@ Java_org_simgrid_msg_Process_migrate(JNIEnv * env, /* change the host java side */ (*env)->SetObjectField(env, jprocess, jprocess_field_Process_host, jhost); } +JNIEXPORT void JNICALL +Java_org_simgrid_msg_Process_setKillTime (JNIEnv *env , jobject jprocess, jdouble jkilltime) { + m_process_t process = jprocess_to_native_process(jprocess, env); + MSG_process_set_kill_time(process, (double)jkilltime); +} diff --git a/src/jmsg_process.h b/src/jmsg_process.h index a97c0ddd40..7d5beadcd3 100644 --- a/src/jmsg_process.h +++ b/src/jmsg_process.h @@ -22,6 +22,9 @@ jfieldID jprocess_field_Process_name; 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); @@ -147,7 +150,7 @@ Java_org_simgrid_msg_Process_nativeInit(JNIEnv *env, jclass cls); /* * Class org_simgrid_msg_Process * Method create - * Signature (Lsimgrid/msg/Host;)V + * Signature (Lorg/simgrid/msg/Host;)V */ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_create(JNIEnv * env, @@ -165,7 +168,7 @@ JNIEXPORT jint JNICALL Java_org_simgrid_msg_Process_killAll /* * Class org_simgrid_msg_Process * Method fromPID - * Signature (I)Lsimgrid/msg/Process; + * Signature (I)Lorg/simgrid/msg/Process; */ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_fromPID (JNIEnv *, jclass, jint); @@ -173,29 +176,29 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_fromPID /* * Class org_simgrid_msg_Process * Method currentProcess - * Signature ()Lsimgrid/msg/Process; + * Signature ()Lorg/simgrid/msg/Process; */ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Process_currentProcess (JNIEnv *, jclass); /* * Class org_simgrid_msg_Process - * Method pause - * Signature (Lsimgrid/msg/Process;)V + * Method suspend + * Signature (Lorg/simgrid/msg/Process;)V */ JNIEXPORT void JNICALL -Java_org_simgrid_msg_Process_pause(JNIEnv * env, +Java_org_simgrid_msg_Process_suspend(JNIEnv * env, jobject jprocess); /* * Class org_simgrid_msg_Process - * Method restart - * Signature (Lsimgrid/msg/Process;)V + * Method resume + * Signature (Lorg/simgrid/msg/Process;)V */ -JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_restart +JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_resume (JNIEnv *, jobject); /* * Class org_simgrid_msg_Process * Method isSuspended - * Signature (Lsimgrid/msg/Process;)Z + * Signature (Lorg/simgrid/msg/Process;)Z */ JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Process_isSuspended (JNIEnv *, jobject); @@ -217,7 +220,7 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_waitFor /* * Class org_simgrid_msg_Process * Method kill - * Signature (Lsimgrid/msg/Process;)V + * Signature (Lorg/simgrid/msg/Process;)V */ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_kill (JNIEnv *, jobject); @@ -225,8 +228,16 @@ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_kill /* * Class org_simgrid_msg_Process * Method migrate - * Signature (Lsimgrid/msg/Host;)V + * Signature (Lorg/simgrid/msg/Host;)V */ JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_migrate (JNIEnv *, jobject, jobject); +/* + * Class org_simgrid_msg_Process + * Method setKillTime + * Signature (D)V + */ +JNIEXPORT void JNICALL Java_org_simgrid_msg_Process_setKillTime + (JNIEnv *, jobject, jdouble); + #endif /* !MSG_JPROCESS_H */ diff --git a/src/jmsg_synchro.c b/src/jmsg_synchro.c index abffec41a6..a5040260ee 100644 --- a/src/jmsg_synchro.c +++ b/src/jmsg_synchro.c @@ -8,6 +8,8 @@ #include "jmsg_synchro.h" #include "jxbt_utilities.h" +XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg); + static jfieldID jsyncro_field_Mutex_bind; JNIEXPORT void JNICALL diff --git a/src/jmsg_task.c b/src/jmsg_task.c index 9eb973c9f6..b7584644b4 100644 --- a/src/jmsg_task.c +++ b/src/jmsg_task.c @@ -56,7 +56,7 @@ Java_org_simgrid_msg_Task_nativeInit(JNIEnv *env, jclass cls) { 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 @@ -410,7 +410,9 @@ Java_org_simgrid_msg_Task_receive(JNIEnv * env, jclass cls, 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; @@ -426,7 +428,7 @@ Java_org_simgrid_msg_Task_receive(JNIEnv * env, jclass cls, 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; @@ -435,15 +437,17 @@ Java_org_simgrid_msg_Task_receive(JNIEnv * env, jclass cls, 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)); diff --git a/src/smx_context_cojava.c b/src/smx_context_cojava.c new file mode 100644 index 0000000000..2905ece3ef --- /dev/null +++ b/src/smx_context_cojava.c @@ -0,0 +1,268 @@ +/* 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 +#include +#include +#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; + +static JavaVM *get_current_vm(void); +static JavaVM *get_current_vm(void) +{ + JavaVM *jvm; + JNI_GetCreatedJavaVMs(&jvm,1,NULL); + return jvm; +} + +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, "", "(Ljava/lang/Runnable;)V"); + xbt_assert((coroutine_init != NULL), "Can't find "); + 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; +} diff --git a/src/smx_context_cojava.h b/src/smx_context_cojava.h new file mode 100644 index 0000000000..1f7a8dea49 --- /dev/null +++ b/src/smx_context_cojava.h @@ -0,0 +1,32 @@ +/* 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 +#include +#include + +#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 */ diff --git a/src/smx_context_java.c b/src/smx_context_java.c index b327df579f..91a3b93114 100644 --- a/src/smx_context_java.c +++ b/src/smx_context_java.c @@ -1,6 +1,6 @@ /* context_java - implementation of context switching for java threads */ -/* 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 @@ -99,6 +99,10 @@ static void* smx_ctx_java_thread_run(void *data) { if (context->super.argc > 0) { (*(context->super.code))(context->super.argc, context->super.argv); } + else { + smx_process_t process = SIMIX_process_self(); + (*env)->SetLongField(env, context->jprocess, jprocess_field_Process_bind, (jlong)process); + } xbt_assert((context->jprocess != NULL), "Process not created..."); //wait for the process to be able to begin //TODO: Cache it @@ -134,7 +138,7 @@ void smx_ctx_java_stop(smx_context_t context) { smx_ctx_java_t ctx_java = (smx_ctx_java_t)context; /* I am the current process and I am dying */ - if (context->iwannadie == -1) { + if (context->iwannadie) { context->iwannadie = 0; JNIEnv *env = get_current_thread_env(); jxbt_throw_by_name(env, "org/simgrid/msg/ProcessKilledError", bprintf("Process killed :)")); diff --git a/src/smx_context_java.h b/src/smx_context_java.h index 4142bf120c..084c5d4ade 100644 --- a/src/smx_context_java.h +++ b/src/smx_context_java.h @@ -1,4 +1,4 @@ -/* 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