Refactor the StopWatch API for easy safe exception handling

The previous StopWatch API was similar to the google commons API in that
it used calls to public start() and stop() methods. This approach is
easy to get wrong if the call to stop() is not placed in a finally{}
clause. Since the task plugin code base did not call stop() from
finally{} clauses, it was succeptible to timers not being stopped, and
other bugs when execeptions were encountered. Since 3.5 uses more
RuntimeExceptions than 2.7, its code base is even more vulnerable to
this. The --task--applicable timings in 3.5 have been suspicious at
times, showing times much longer than possible. This is believed to be
due to accumulated overlapping StopWatch timings due to some of them not
being stopped when RuntimeExceptions are encountered with INVALID tasks.

Redesign the StopWatch as an AutoCloseable and provide easy APIs to use
it safely in a try-with-resource, or with SAMs, and adapt the callers to
use the new APIs.

Change-Id: Ie3073c9f3d69435b67b12678f8c0f255339c76cc
8 files changed