lockprof: move panic check after inspecting the state
(cherry picked from commit e2ab16b1a6c0f556299df21be54f04652ba7169d)