  The observed wide eccentricity distribution of extrasolar giant planets is
thought to be the result of dynamical instabilities and gravitational
scattering among planets. Previously, it has been assumed that the orbits in
giant planet systems become gravitationally unstable after the gas nebula
dispersal. It was not well understood, however, how these unstable conditions
were established in the first place.
  In this work we numerically simulate the evolution of systems of three
planets as the planets sequentially grow to Jupiter's mass, and dynamically
interact among themselves and with the gas disk. We use the hydro-dynamical
code FARGO that we modified by implementing the $N$-body integrator SyMBA. The
new code can handle close encounters and collisions between planets. To test
their stability, the planetary systems were followed with SyMBA for up to
$10^8$ yr after the gas disk dispersal.
  We find that dynamics of the growing planets is complex, because migration
and resonances raise their orbital eccentricities, and cause dynamical
instabilities when gas is still around. If the dynamical instabilities occur
early, planets can be removed by collisions and ejections, and the system
rearranges into a new, more stable configuration. In this case, the planetary
systems emerging from the gas disks are expected to be stable, and would need
to be destabilized by other means (low-mass planets, planetesimal disks, etc.).
Alternatively, for the giant planet system to be intrinsically unstable upon
the gas disk dispersal, a special timing would be required with the growth of
(at least some of) the giant planets having to occur near the end of the gas
disk lifetime.
