The word Troll was originally used to translate from Sindarin (the elvish tongue) Torog.
In the beginning of times when Melkor (We'll get to Melkor later) ruled the dark lands in the North, trolls were stupid and didn't have a better communication than animals, but Sauron (Melkor's right hand) taught them whatever they could learn and using their evil nature, he increased their intelligence.
Trolls were close to Orcs in the dark lands, so eventually Trolls ended up taking words here and there from orcish and later on in the second age, trolls would speak a corrupted form of the common tongue.
By the third age, a new breed of trolls formed south of the dark woods near Mordor, and these trolls weren't normal, they were called Olog-Hai in the black tongue. It was obvious that Sauron breeded them, but nobody knows how he achieved it. These trolls were full of evil from Sauron, and they were fast, agile, fierce, savage and cunning, making them a terrible foe, especially against the weakened men and what was left of the elves and dwarves. These trolls were able to endure sunlight as long as Sauron's will was upon them.
Olog-Hai by Eallgrenemearcweard on Deviantart