Numerical simulations are presented to study the stability of gaps opened by giant planets in 3D self-gravitating disks. In weakly self-gravitating disks, a few vortices develop at the gap edge and merge on orbital time-scales. The result is one large but weak vortex with Rossby number -0.01. In moderately self-gravitating disks, more vortices develop and their merging is resisted on dynamical time-scales. Self-gravity can sustain multi-vortex configurations, with Rossby number -0.2 to -0.1, over a time-scale of order 100 orbits. Self-gravity also enhances the vortex vertical density stratification, even in disks with initial Toomre parameter of order 10. However, vortex formation is suppressed in strongly self-gravitating disks and replaced by a global spiral instability associated with the gap edge which develops during gap formation.