We studied the influence of the growth temperature and Mg flux on the morphology, polarity inversion and p-type conductivity in GaN:Mg layers grown by plasma-assisted molecular beam epitaxy (PAMBE). Polarity-dependent wet etching, secondary ion mass spectroscopy and transmission electron microscopy are used to determine the polarity inversion of heavily Mg-doped GaN layers. Phase diagram for polarity inversion effect as a function of substrate temperature and Mg flux is presented. The maximum hole concentration measured in Hall effect experiments is 5×10 17 cm −3 for Mg concentration of 10 20 cm −3 .