Gunwales: The upper edge of a ship's side; in large vessels, the uppermost planking, which covers the timber-heads and reaches from the quarter-deck to the forecastle on either side; in small craft, a piece of timber extending round the top side of
hull.
The expressions 'full to the gunwales' or 'packed to the gunwales' were first used as literal references to heavily loaded ships. 'Gunwales' may have been a 15th century word, but there's no mention of the phrase until the 19th century, as in the Unitarian periodical, The Monthly Repository, 1834:
This is the Island of the Golden Fruit. Look, yonder they come! boats - one, two, three, five, a dozen! all laden up to the gunwales with the juicy balls.