Can't speak to AC specifically, but most airlines also use fare class as a differentiator as well, with the highest fare class on top of the list. Others include time of checkin as a last minute tie breaker - say those 5 E's were all flying the same class of fare and there was one op up needed to be given out, then the one that checked in first would likely get it.
As for partner airlines like UA or LH, they will always upgrade their own elites before even their partners, so UA would do 1K's, followed by Premier Exec's, then Premier and then start with the *G's from other carriers. And honestly, probably not worth thinking about too much, since the chance of it happening on a partner carrier is very low. At UA, the exception will probably be E+ upgrades, which will usually be doled out to *G's and *S's for free when they there aren't enough UA elites/buy ups and too many in E-.