Class UIFreezeWatchdog
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
FieldsModifier and TypeFieldDescriptionstatic final intThe 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 StringThe first words of the line that follows a dump once the SWT thread handles events again.static final StringThe prefix of the dump files in the console's log directory.static final StringThe first words of a dump.static final intThe count of dump files kept.static final intThe bounds of the threshold a system property may set, in seconds.static final intThe bounds of the threshold a system property may set, in seconds.static final StringThe system property that turns the dump off:-Diizi.uiFreezeDump=off.static final StringThe system property that sets the threshold in seconds:-Diizi.uiFreezeDump.seconds=<n>.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionvoidbegin()Starts the watchdog's thread.voidend()Ends the watchdog: its thread ends, the beat ends at its next run.longThe count of dumps written.The file of the last dump.booleanTells whether the beat runs.static booleanTells whether a value ofOFF_PROPERTYturns the dump off.static booleanTells whether iiziGo's watchdog runs.static intThe threshold a value ofSECONDS_PROPERTYgives.static booleanstart()Starts iiziGo's watchdog, once: the workbench's Display, the threshold ofSECONDS_PROPERTYorDEFAULT_SECONDS, the console's log directory, the dump logged as a WARNING.static booleanstop()Stops iiziGo's watchdog.
Field Details
OFF_PROPERTY
The system property that turns the dump off:-Diizi.uiFreezeDump=off.- See Also:
SECONDS_PROPERTY
The system property that sets the threshold in seconds:-Diizi.uiFreezeDump.seconds=<n>.- See Also:
DEFAULT_SECONDS
public static final int DEFAULT_SECONDSThe 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_SECONDSThe bounds of the threshold a system property may set, in seconds.- See Also:
MAX_SECONDS
public static final int MAX_SECONDSThe bounds of the threshold a system property may set, in seconds.- See Also:
FREEZE
ENDED
The first words of the line that follows a dump once the SWT thread handles events again.- See Also:
FILE_PREFIX
The prefix of the dump files in the console's log directory.- See Also:
KEEP_FILES
public static final int KEEP_FILESThe 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 bystart(); 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 ofSECONDS_PROPERTYorDEFAULT_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
Tells whether a value ofOFF_PROPERTYturns the dump off.- Parameters:
value- The value, null for not set.- Returns:
- true for "off" (in any case, blanks around it ignored).
seconds
The threshold a value ofSECONDS_PROPERTYgives.- Parameters:
value- The value, null for not set.- Returns:
- The seconds: the value when it is a number from
MIN_SECONDStoMAX_SECONDS, a number outside them brought to the nearer bound,DEFAULT_SECONDSfor 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
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.