Electrical characterization of Mg-related energy levels and the compensation mechanism in GaN : Mg