--- /dev/null
+set(example java_semaphore_gc)
+set(sources
+ ${CMAKE_CURRENT_SOURCE_DIR}/SemaphoreGC.java
+ )
+
+if(enable_java)
+ add_custom_command(
+ COMMENT "Building ${example}..."
+ OUTPUT ${example}_compiled
+ DEPENDS ${sources} simgrid-java_jar ${SIMGRID_JAR}
+ COMMAND ${JAVA_COMPILE} -classpath ${SIMGRID_JAR}
+ -d ${CMAKE_CURRENT_BINARY_DIR}/.. ${sources}
+ COMMAND ${CMAKE_COMMAND} -E remove ${example}_compiled
+ COMMAND ${CMAKE_COMMAND} -E touch ${example}_compiled
+ )
+ add_custom_target(${example} ALL DEPENDS ${example}_compiled)
+endif()
+
+set(tesh_files
+ ${tesh_files}
+ ${CMAKE_CURRENT_SOURCE_DIR}/semaphore_gc.tesh
+ PARENT_SCOPE
+ )
+set(xml_files
+ ${xml_files}
+ PARENT_SCOPE
+ )
+set(examples_src
+ ${examples_src}
+ ${sources}
+ PARENT_SCOPE
+ )
+set(bin_files
+ ${bin_files}
+ PARENT_SCOPE
+ )
+set(txt_files
+ ${txt_files}
+ PARENT_SCOPE
+ )
--- /dev/null
+/* Copyright (c) 2016. 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. */
+
+/* This test ensures that the used semaphores are not garbage-collected while we still use it.
+ * This was reported as bug #... on gforge.
+ */
+
+package semaphore;
+
+import org.simgrid.msg.*;
+import org.simgrid.msg.Process;
+import org.simgrid.trace.Trace;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Random;
+
+class SemCreator extends Process {
+ Semaphore sem;
+
+ SemCreator(Host h, String n){
+ super(h, n);
+ }
+
+ public void main(String[] args) throws MsgException{
+ int j;
+ Msg.info("Creating 150 new Semaphores, yielding and triggering a GC after each");
+ for(j = 1; j <= 150; j++) {
+ sem = new Semaphore(0);
+ waitFor(10);
+ System.gc();
+ }
+ Msg.info("It worked, we survived. The test is passed.");
+ }
+}
+
+
+public class SemaphoreGC {
+ public static void main(String[] args) throws Exception {
+
+ Msg.init(args);
+ if (args.length < 1) {
+ Msg.info("Usage: java -cp simgrid.jar:. semaphore.SemaphoreGC <deployment.xml>");
+ System.exit(1);
+ }
+ Msg.createEnvironment(args[0]);
+
+ Host[] hosts = Host.all();
+ new SemCreator(hosts[0], "SemCreator").start();
+
+ Msg.run();
+ }
+
+}
--- /dev/null
+$ java -classpath ${classpath:=.} semaphore.SemaphoreGC ${srcdir:=.}/../../examples/platforms/small_platform.xml "--log=root.fmt:[%10.4r]%e(%i:%P@%h)%e%m%n"
+> [ 0.0000] (0:maestro@) Using regular java threads.
+> [ 0.0000] (1:SemCreator@Fafard) Creating 150 new Semaphores, yielding and triggering a GC after each
+> [ 1500.0000] (1:SemCreator@Fafard) It worked, we survived. The test is passed.
+> [ 1500.0000] (0:maestro@) MSG_main finished; Cleaning up the simulation...
add_subdirectory(${CMAKE_HOME_DIRECTORY}/examples/xbt)
add_subdirectory(${CMAKE_HOME_DIRECTORY}/teshsuite/java)
+add_subdirectory(${CMAKE_HOME_DIRECTORY}/teshsuite/java/semaphore)
add_subdirectory(${CMAKE_HOME_DIRECTORY}/teshsuite/java/sleep_host_off)
add_subdirectory(${CMAKE_HOME_DIRECTORY}/teshsuite/mc)
# teshsuite ones
ADD_TESH(tesh-java-sleep-host-off --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/teshsuite/java ${CMAKE_HOME_DIRECTORY}/teshsuite/java/sleep_host_off/sleep_host_off.tesh)
+ ADD_TESH(tesh-java-semaphore-gc --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/java --setenv classpath=${TESH_CLASSPATH} --cd ${CMAKE_BINARY_DIR}/teshsuite/java ${CMAKE_HOME_DIRECTORY}/teshsuite/java/semaphore/semaphore_gc.tesh)
ENDIF()