Class UIFreezeWatchdog

java.lang.Object
com.iizigo.swt.UIFreezeWatchdog

public final class UIFreezeWatchdog extends Object
The UI-freeze dump of iiziGo (CC-FIX-DESIGNER-MARKER-DEADLOCK, ruling GD-1 row 2): when the SWT thread has handled no event for DEFAULT_SECONDS seconds, ONE thread dump is written to the IIZI Console log and to a file of the console's log directory, the frozen SWT thread first. It never stops, kills or interrupts anything.

Why. The gate of r22226 stopped for 74 minutes on a deadlock between the SWT thread and a job (PropMarker.createMarker says which). ThreadDeadlockDetector runs in iiziGo and said nothing: the JVM finds cycles of monitors and of java.util.concurrent locks only, and the SWT thread waited for the workspace lock, which is an Eclipse lock (an Object.wait in OrderedLock). Whatever a freeze is made of - such a cycle, an endless loop, a wait for something that never comes - the SWT thread handles no event, and that is what is watched here.

How. A timer of the Display runs in the SWT thread once a second and counts (the beat): timers run in the event loop, also in the loop of a modal dialog, so a thread that handles events beats. A daemon thread looks at the count every 5000L ms. Ticks without a beat add up - each at most twice the tick, so a computer that slept or a JVM held by a debugger does not count as a freeze - and at the threshold the dump is written, once: the next dump can come only after the thread has moved again (a beat), which is logged in one line. The watchdog's thread calls nothing of SWT except the one post that starts the beat, made with no monitor held (R-436), and waits for no lock of SWT or Eclipse, so it cannot become part of what it watches: the Display's thread, which is needed for a freeze that begins before the first beat, is asked for on a thread of its own (Display.getThread() takes the lock of the Device class) and waited for two seconds at most. Once the disposal of the Display has begun the beat ends; an exit that then does not end within the threshold is dumped as well.

The dump. The SWT thread with its stack, the monitors it holds and what it waits for; then the owners of what it waits for, one after the other (monitors and java.util.concurrent locks from the JVM, the workspace lock from Eclipse when the SWT thread stands in WorkManager.checkIn); the holder of the workspace lock and the Eclipse jobs with their states, threads and rules; then every platform thread. The file holds the same text, followed by every thread of the JVM with the virtual threads, in the form of jcmd Thread.dump_to_file. The newest 10 files are kept.

Cost. One timer of the Display a second (it adds one to a counter), and a daemon thread that compares two numbers every five seconds. A dump costs what a thread dump costs, once per freeze.

Switches. -Diizi.uiFreezeDump=off turns it off; -Diizi.uiFreezeDump.seconds=<n> sets the threshold (5 to 3600).

Author:
Christopher Mindus
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The threshold in seconds: long enough that an ordinary long operation in the SWT thread (a large Module opened, a build started from a dialog) passes without a dump, short enough that the dump of a real freeze is there before a person gives up and ends iiziGo.
    static final String
    The first words of the line that follows a dump once the SWT thread handles events again.
    static final String
    The prefix of the dump files in the console's log directory.
    static final String
    The first words of a dump.
    static final int
    The count of dump files kept.
    static final int
    The bounds of the threshold a system property may set, in seconds.
    static final int
    The bounds of the threshold a system property may set, in seconds.
    static final String
    The system property that turns the dump off: -Diizi.uiFreezeDump=off.
    static final String
    The system property that sets the threshold in seconds: -Diizi.uiFreezeDump.seconds=<n>.
  • Constructor Summary

    Constructors
    Constructor
    Description
    UIFreezeWatchdog(Supplier<Display> displays, long thresholdMillis, long tickMillis, long beatMillis, File directory, Consumer<String> log)
    Creates a watchdog: iiziGo's own is made by start(); a test makes one with a short threshold.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Starts the watchdog's thread.
    void
    end()
    Ends the watchdog: its thread ends, the beat ends at its next run.
    long
    The count of dumps written.
    The file of the last dump.
    boolean
    Tells whether the beat runs.
    static boolean
    isOff(String value)
    Tells whether a value of OFF_PROPERTY turns the dump off.
    static boolean
    Tells whether iiziGo's watchdog runs.
    static int
    seconds(String value)
    The threshold a value of SECONDS_PROPERTY gives.
    static boolean
    Starts iiziGo's watchdog, once: the workbench's Display, the threshold of SECONDS_PROPERTY or DEFAULT_SECONDS, the console's log directory, the dump logged as a WARNING.
    static boolean
    Stops iiziGo's watchdog.
  • Field Details

    • OFF_PROPERTY

      public static final String OFF_PROPERTY
      The system property that turns the dump off: -Diizi.uiFreezeDump=off.
      See Also:
    • SECONDS_PROPERTY

      public static final String SECONDS_PROPERTY
      The system property that sets the threshold in seconds: -Diizi.uiFreezeDump.seconds=<n>.
      See Also:
    • DEFAULT_SECONDS

      public static final int DEFAULT_SECONDS
      The threshold in seconds: long enough that an ordinary long operation in the SWT thread (a large Module opened, a build started from a dialog) passes without a dump, short enough that the dump of a real freeze is there before a person gives up and ends iiziGo.
      See Also:
    • MIN_SECONDS

      public static final int MIN_SECONDS
      The bounds of the threshold a system property may set, in seconds.
      See Also:
    • MAX_SECONDS

      public static final int MAX_SECONDS
      The bounds of the threshold a system property may set, in seconds.
      See Also:
    • FREEZE

      public static final String FREEZE
      The first words of a dump.
      See Also:
    • ENDED

      public static final String ENDED
      The first words of the line that follows a dump once the SWT thread handles events again.
      See Also:
    • FILE_PREFIX

      public static final String FILE_PREFIX
      The prefix of the dump files in the console's log directory.
      See Also:
    • KEEP_FILES

      public static final int KEEP_FILES
      The count of dump files kept.
      See Also:
  • Constructor Details

    • UIFreezeWatchdog

      public UIFreezeWatchdog(Supplier<Display> displays, long thresholdMillis, long tickMillis, long beatMillis, File directory, Consumer<String> log)
      Creates a watchdog: iiziGo's own is made by start(); a test makes one with a short threshold.
      Parameters:
      displays - Gives the Display to watch, null while there is none; asked from the watchdog's thread.
      thresholdMillis - The time without an event after which the dump is written.
      tickMillis - The interval of the watchdog's look.
      beatMillis - The interval of the beat in the SWT thread.
      directory - The directory of the dump files, created when missing.
      log - Receives the dump, and the line that says the freeze ended.
  • Method Details

    • start

      public static boolean start()
      Starts iiziGo's watchdog, once: the workbench's Display, the threshold of SECONDS_PROPERTY or DEFAULT_SECONDS, the console's log directory, the dump logged as a WARNING.
      Returns:
      true when started, false when it runs already or is turned off.
    • stop

      public static boolean stop()
      Stops iiziGo's watchdog.
      Returns:
      true when stopped, false when it did not run.
    • isStarted

      public static boolean isStarted()
      Tells whether iiziGo's watchdog runs.
      Returns:
      true if it was started and not stopped.
    • isOff

      public static boolean isOff(String value)
      Tells whether a value of OFF_PROPERTY turns the dump off.
      Parameters:
      value - The value, null for not set.
      Returns:
      true for "off" (in any case, blanks around it ignored).
    • seconds

      public static int seconds(String value)
      The threshold a value of SECONDS_PROPERTY gives.
      Parameters:
      value - The value, null for not set.
      Returns:
      The seconds: the value when it is a number from MIN_SECONDS to MAX_SECONDS, a number outside them brought to the nearer bound, DEFAULT_SECONDS for anything else.
    • begin

      public void begin()
      Starts the watchdog's thread.
    • end

      public void end()
      Ends the watchdog: its thread ends, the beat ends at its next run.
    • getDumpCount

      public long getDumpCount()
      The count of dumps written.
      Returns:
      The count.
    • getLastFile

      public File getLastFile()
      The file of the last dump.
      Returns:
      The file, null for none or when it could not be written.
    • isBeating

      public boolean isBeating()
      Tells whether the beat runs.
      Returns:
      true once the first beat came.