Here is one thread on the topic:
http://www.flyertalk.com/forum/showthread.php?t=18328
Here's a summary based on how I understand it.
Only Captains are entitled to a confirmed J seat if they are deadheading. F/Os and FAs can get a J seat on a space available basis and they are awarded based on seniority. This is all governed by the respective collective agreements. I'm not sure if employees deadheading to work a flight get a higher priority than employees deadheading home after operating a flight.
Entitled customers (paid or upgraded) will not be bumped from a J class seat and AFAIK, the upgrade list at the gate is cleared before employees are cleared into J class - which would explain why crew were milling around the gate.
This topic can be a sore spot on this forum where some beleive that E/SE should be operationally upgraded (op up'd) before crew even if they are not on a eligible fare and/or do not have a cert to upgrade.
There are some very knowledgeable AC staffers on this forum that could correct or add to any of this.