-/* Copyright (c) 2006-2019. The SimGrid Team. All rights reserved. */
+/* Copyright (c) 2006-2021. 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 org.simgrid.msg;
-import java.lang.management.ManagementFactory;
-import java.lang.management.ThreadInfo;
-import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
/**
* A process may be defined as a code, with some private data, executing
* declared in the deployment file (XML format).
* To create your own process you must inherit your own process from this
* class and override the method "main()". For example if you want to use
- * a process named Slave proceed as it :
+ * a process named Worker proceed as it :
*
* (1) import the class Process of the package simgrid.msg
* import simgrid.msg.Process;
*
- * public class Slave extends simgrid.msg.Process {
+ * public class Worker extends simgrid.msg.Process {
*
* (2) Override the method function
*
* \endverbatim
* }
* The name of your process must be declared in the deployment file of your simulation.
- * For the example, for the previous process Slave this file must contains a line :
- * <process host="Maxims" function="Slave"/>, where Maxims is the host of the process
- * Slave. All the process of your simulation are automatically launched and managed by Msg.
+ * For the example, for the previous process Worker this file must contains a line :
+ * <process host="Maxims" function="Worker"/>, where Maxims is the host of the process
+ * Worker. All the process of your simulation are automatically launched and managed by Msg.
* A process use tasks to simulate communications or computations with another process.
* For more information see Task. For more information on host concept
* see Host.
*
*
*/
- public Process(String hostname, String name) throws HostNotFoundException {
+ protected Process(String hostname, String name) throws HostNotFoundException {
this(Host.getByName(hostname), name, null);
}
/**
* @exception HostNotFoundException if no host with this name exists.
*
*/
- public Process(String hostname, String name, String[] args) throws HostNotFoundException {
+ protected Process(String hostname, String name, String[] args) throws HostNotFoundException {
this(Host.getByName(hostname), name, args);
}
/**
* @param name The name of the process.
*
*/
- public Process(Host host, String name) {
+ protected Process(Host host, String name) {
this(host, name, null);
}
/**
* @param name The name of the process.
* @param argsParam The arguments of main method of the process.
*/
- public Process(Host host, String name, String[]argsParam)
+ protected Process(Host host, String name, String[]argsParam)
{
if (host == null)
throw new IllegalArgumentException("Cannot create a process on the null host");
* @param killTime Kill time of the process
*
*/
- public Process(Host host, String name, String[]args, double startTime, double killTime) {
+ protected Process(Host host, String name, String[]args, double startTime, double killTime) {
this(host, name, args);
this.startTime = startTime;
this.killTime = killTime;
public native void migrate(Host host);
/**
* Makes the current process sleep until millis milliseconds have elapsed.
- * You should note that unlike "waitFor" which takes seconds, this method takes milliseconds.
- * FIXME: Not optimal, maybe we should have two native functions.
+ * You should note that unlike "waitFor" which takes seconds (as usual in SimGrid), this method takes milliseconds (as usual for sleep() in Java).
+ *
* @param millis the length of time to sleep in milliseconds.
*/
public static void sleep(long millis) throws HostFailureException {
Msg.info("Unexpected behavior. Stopping now");
System.exit(1);
}
- catch(ProcessKilledError pk) {
- /* The process was killed before its end. With a kill() or something. */
- //Msg.info("Forwarding a PKE");
- throw pk;
- }
+ /* Let the ProcessKilledError (that we'd get if the process is forcefully killed) flow back to the caller */
}
/**
public static native int getCount();
public static void debugAllThreads() {
- final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
- long[] deads = threadMXBean.findDeadlockedThreads();
- if (deads != null)
- for (long dead : deads)
- System.err.println("Thread deadlocked: "+dead);
-
- // Search remaining threads that are not main nor daemon
- List<Long> ids = new ArrayList<>();
- for (Thread t : Thread.getAllStackTraces().keySet()) {
+ // Search remaining threads that are not main nor daemon
+ for (Thread t : Thread.getAllStackTraces().keySet())
if (! t.isDaemon() && !t.getName().equals("main"))
- ids.add(t.getId());
- }
- if (ids.size() > 0) {
- long[] id_array = new long[ids.size()];
- for (int i=0; i<ids.size(); i++)
- id_array[i] = ids.get(i);
-
- final ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(id_array, true, true);
- final StringBuilder dump = new StringBuilder();
- for (ThreadInfo threadInfo : threadInfos) {
- dump.append('"');
- dump.append(threadInfo.getThreadName());
- dump.append("\" ");
- final Thread.State state = threadInfo.getThreadState();
- dump.append("\n java.lang.Thread.State: ");
- dump.append(state);
- final StackTraceElement[] stackTraceElements = threadInfo.getStackTrace();
- for (final StackTraceElement stackTraceElement : stackTraceElements) {
- dump.append("\n at ");
- dump.append(stackTraceElement);
- }
- dump.append("\n In native? "+threadInfo.isInNative()+"\n");
- dump.append(" Suspended? "+threadInfo.isSuspended()+"\n");
- dump.append(" Waiting for: "+threadInfo.getLockInfo()+"\n");
- dump.append("\n\n");
- }
- System.err.println(dump);
- }
+ System.err.println("Thread "+t.getName()+" is still running! Please report that bug");
}
}