1.1 --- a/src/share/vm/utilities/ostream.hpp Wed Feb 09 15:02:23 2011 -0800 1.2 +++ b/src/share/vm/utilities/ostream.hpp Tue Feb 22 15:26:36 2011 -0800 1.3 @@ -123,18 +123,36 @@ 1.4 1.5 // advisory locking for the shared tty stream: 1.6 class ttyLocker: StackObj { 1.7 + friend class ttyUnlocker; 1.8 private: 1.9 intx _holder; 1.10 1.11 public: 1.12 static intx hold_tty(); // returns a "holder" token 1.13 static void release_tty(intx holder); // must witness same token 1.14 + static bool release_tty_if_locked(); // returns true if lock was released 1.15 static void break_tty_lock_for_safepoint(intx holder); 1.16 1.17 ttyLocker() { _holder = hold_tty(); } 1.18 ~ttyLocker() { release_tty(_holder); } 1.19 }; 1.20 1.21 +// Release the tty lock if it's held and reacquire it if it was 1.22 +// locked. Used to avoid lock ordering problems. 1.23 +class ttyUnlocker: StackObj { 1.24 + private: 1.25 + bool _was_locked; 1.26 + public: 1.27 + ttyUnlocker() { 1.28 + _was_locked = ttyLocker::release_tty_if_locked(); 1.29 + } 1.30 + ~ttyUnlocker() { 1.31 + if (_was_locked) { 1.32 + ttyLocker::hold_tty(); 1.33 + } 1.34 + } 1.35 +}; 1.36 + 1.37 // for writing to strings; buffer will expand automatically 1.38 class stringStream : public outputStream { 1.39 protected: