Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines with new year.
[simgrid.git] / src / bindings / java / org / simgrid / msg / Process.java
index 0fb5c6f..5eeb952 100644 (file)
@@ -1,16 +1,12 @@
-/* Copyright (c) 2006-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2006-2020. 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
@@ -257,8 +253,8 @@ public abstract class Process implements Runnable {
        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  {
@@ -303,11 +299,7 @@ public abstract class Process implements Runnable {
                        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 */
        }
 
        /**
@@ -338,43 +330,9 @@ public abstract class Process implements Runnable {
        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");
         }
 }