It has a mass of approximately 6.58 zettatons (according to my extrapolated size category weights, that should fall under the approximate mass of a Mega-Titanic creature, 1-8 zettatons), and with the rule that inanimate objects have hp equivalent to the bonus hp that a construct of their weight would have received, the earth has approximately 122,880 hp. However, if the earth were to be turned into an animated object, it receives HD since it's now a construct, and using the rule that spherical creatures have HD equivalent to the creature's diameter in feet (the earth has a mean diameter of about 7,919.744939553 miles), the earth is now a 41,816,253 HD Mega-Colossal animated object. That obviously has a lot more hp than when it was as just an inanimate planet, and that's not even including its construct bonus hp.
Let's try a sentient earth from a different approach by instead creating a golem in its likeness. According to the bestiary, a golem's HD is equivalent to [9 + 1/2 Material Strength Modifier], adjusted by the size of the golem. Since a Huge golem is x2, a Gargantuan golem is x4, a Colossal golem is x8, and a Titanic golem is x16, we can extrapolate from this doubling progression the following table:
Macro-Fine = x32
Macro-Diminutive = x64
Macro-Tiny = x128
Macro-Small = x256
Macro-Medium = x512
Macro-Large = x1,024
Macro-Huge = x2,048
Macro-Gargantuan = x4,096
Macro-Colossal = x8,192
Macro-Titanic = x16,384
Mega-Fine = x32,768
Mega-Diminutive = x65,536
Mega-Tiny = x131,072
Mega-Small = x262,144
Mega-Medium = x524,288
Mega-Large = x1,048,576
Mega-Huge = x2,097,152
Mega-Gargantuan = x4,194,304
Mega-Colossal = x8,388,608
A Mega-Colossal creature with humanoid proportions would have a height of 12,288-24,576 miles, and we half that for the diameter of a spherical creature (bringing it down to 6,144-12,288 miles), and since the earth has a mean diameter of 7,919.744939553 miles, the earth is a Mega-Colossal creature. The earth has a density of 5.513 grams per cubic centimeter which means it would weigh approximately 4.6 times heavier than a creature made of flesh and bone (1.2 grams per cubic centimeter), giving "earth material" (consider things fashioned from it having a crust, mantle, and core) a material strength modifier of +23. Therefore, a Mega-Colossal golem made of "earth material" would have HD equivalent to [(9 + 11) x 8,388,608]. Thus, a Mega-Colossal spherical golem with the exact composition and density of the earth would have 167,772,160 HD.
So why exactly does a creature with the exact dimensions and density of the earth have millions more hp than just the earth? And why does a golem with the composition and size of the earth also have millions more hp than a non-golem creature with the size and material of the earth?