to give one a comforting feeling of contentment
The noun cockle now denotes specifically an edible burrowing bivalve mollusc with a strong ribbed shell common on sandy coasts (Genus Cardium, family Cardiidae). But it was formerly applied more vaguely to other bivalves and their shells.
This is because this word is from Old French coquille, meaning shell (with the English shifting of stress, the original Middle English form cokille has become cockle, like gentille, gentle). In his textbook Lesclarcissement de la langue francoyse (1530), the teacher and scholar of languages John Palsgrave translated both the English terms coccle fysshe and cokell shell as French coquille.
The expression the cockles of one’s heart is first recorded in Some Observations upon the Answer to an Enquiry into the Grounds and Occasions of the Contempt of the Clergy (1671), by the college head John Eachard (1637-97):
I am confident of it, that this contrivance of his, did inwardly as much rejoice the cockles of his heart, as he fancies, that what I writ did sometimes much tickle my spleen.
In the Latin Tractatus de Corde (A Treatise on the Heart – 1669), the physician and physiologist Richard Lower (1631-91) wrote, about the muscular fibres of the ventricles:
Fibræ [...] spirali suo ambitu Helicem sive cochleam satis aptè referunt.
These fibres [...], with their spiral circuit, may rather aptly be referred to as a Helix or snail-shell*.
* In Traité du Cœur, the 1679 French translation of Lower’s treatise, cochlea is rendered as coquille de limaçon, snail-shell. In classical Latin, cochlea, or coclea, meant snail and snail-shell (in English, the spiral cavity of the inner ear is called cochlea, because its shape resembles that of a snail-shell). However, the meaning seems to have been different in post-classical Latin, since in the English-Latin dictionary Promptorium parvulorum sive clericorum (Storehouse for Children or Clerics - around 1440), Latin coclea translates English cocle defined as “fysche”.
In any case, Lower’s text might be a hint as to the origin of the expression: the ventricles of the heart might have been called cochleæ cordis**, and this might have been turned into cockles of one’s heart.
(** Latin cor/cordis: heart - cf. English courage)
According to another explanation, cockle in the expression is from the Latin term of endearment corculum, little heart, diminutive of cor. For example, in Folk-Etymology, a dictionary of verbal corruptions or words perverted in form or meaning, by false derivation or mistaken analogy (1882), A. Smythe Palmer wrote:
In default of a better I make the following suggestion. As we find ‘corke’, a provincial word for the ‘core’ or heart of fruit, so ‘cockle’ may be for ‘corcle’, ‘corkle’, or ‘corcule’, an adaptation of the Latin ‘corculum’, a little heart, and the expression would mean the ‘core’ (French ‘cœur’), or “heart of heart”, but why the word occurs in the plural I cannot say.
According to a widespread theory, the explanation lies in the zoological name for the cockle, Cardium, from Greek καρδία (kardia), heart (cf. English cardiac).
But this theory overlooks the fact that the expression appeared in 1671, whereas zoological nomenclature started in the 10th edition (1758) of Systema Naturæ, by the Swedish natural historian and physician Carolus Linnaeus (Carol von Linné – 1707-78). The earliest mention of Cardium designating the cockle that I could find in an English text is in Lectures on the Materia Medica (1773), by William Cullen, professor of medicine at the University of Edinburgh:
These were formerly confounded partly with the Fishes; for the reasons of classing them separately, vide Linnaeus, vol. I. Systema Naturæ. They are of ﬁve orders, two only of which are used as aliment, the Mollusca and Testacea. Of the Mollusca, [...] Cardium edule, the Cockle; Cardium echinatum, prickly Cockle.
The explanation might simply be that the expression is based on the comparison between the shape of the heart and that of a cockleshell – or of the body it protects.