Homoepitaxial GaN films, doped with Mg, were grown by rf-plasma molecular-beam epitaxy on Ga-polarity (0001) templates. Convergent-beam electron diffraction analysis establishes that the film polarity changes from [0001] to [000 (1) under bar] when the Mg flux during growth is approximately 1 ML/s. Secondary ion mass spectrometry indicates a doping concentration of similar to 10(20) cm(-3) in the film where the inversion occurs, and a reduced Mg incorporation in the [000 (1) under bar] material. Transmission electron microscopy shows that the inversion domain boundary is faceted predominantly along the {0001} and {h,h,-2h,l} planes, with l/h approximately equal to 3. Using first-principles total energy calculations, we show that the {h,h,-2h,l} segments of the boundary are stabilized by the incorporation of Mg in threefold coordinated lattice sites. (C) 2000 American Institute of Physics. [S0003- 6951(00)03042-4].