The high density of the recently discovered close-in extrasolar planet HD149026b suggests the presence of a huge core in the planet , which challenges planet formation theory . We first derive constraints on the amount of heavy elements and hydrogen/helium present in the planet : We find that preferred values of the core mass are between 50 and 80 { M } _ { \oplus } , although a minimum value of the core mass is \sim 35 { M } _ { \oplus } in the extreme case of formation of the planet at > 0.5 AU , followed by late inward migration after > 1 Ga and negligible reheating due to tidal dissipation . We then investigate the possibility of subcritical core accretion as envisioned for Uranus and Neptune . We show that a massive core surrounded by an envelope in hydrostatic equilibrium with the gaseous disk may indeed grows beyond 30 { M } _ { \oplus } provided the core accretion rate remains larger than \sim 2 \times 10 ^ { -5 } { M } _ { \oplus } yr ^ { -1 } . However , we find the subcritical accretion scenario is very unlikely in the case of HD149026b for at least two reasons : ( i ) Subcritical planets are such that the ratio of their core mass to their total mass is above \sim 0.7 , in contradiction with constraints for all but the most extreme interior models of HD149026b ; ( ii ) High accretion rates and large isolation mass required for the formation of a subcritical > 35 { M } _ { \oplus } core are possible only at specific orbital distances in a disk with a surface density of dust equal to at least 10 times that of the minimum mass solar nebula . This value climbs to 30 when considering a 50 { M } _ { \oplus } core . These facts point toward two main routes for the formation of this planet : ( i ) Gas accretion that is limited by a slow viscous inflow of gas in an evaporating disk ; ( ii ) A significant modification of the composition of the planet after gas accretion has stopped . These two routes are not mutually exclusive . Illustrating the second route , we show that for a wide range of impact parameters , giant impacts lead to a loss of the gas component of the planet and thus may lead to planets that are highly enriched in heavy elements . Alternatively , the planet may be supplied with heavy elements by planetesimals by secular perturbations . Both in the giant impact and the secular perturbation scenarios , we expect an outer giant planet to be present . Observational studies by imaging , astrometry and long term interferometry of this system are needed to better narrow down the ensemble of possibilities .