writing or speech that identifies the speaker as belonging to a certain social class,

I have never considered that grammar is essentially a matter of class. (Although I am very aware that there can be a high degree of snobbishness attached to it by the "snooty, elite but necessary" sort of person)

Grammar has much more, I would submit, to do with clarity an lack of ambiguity than anything else. It's all very good and proper to say, "We don' wan' no steenkin' rules," and my anarchist background and beliefs supports me in that view of unnecessary rules. But to dispense with rules altogether leads, not to anarchy but to chaos.
(as an aside, it is interesting to note that the longest list of house rules I've ever encountered were hung on the back door of an anarchist community in Yorkshire.)

The grammar that we have grown up with was certainly imposed by the top few percent of society, for the good reasons that they were the ones with education, and the ones to whom clarity and unambiguity were most important (for the business of governing and control, etc.) Other communities developed their own set of customs and rules which, though different, were just as strictly observed.
Now that the bulk of the societies that we on this board live in are educated (at least to a point) grammar is no longer being dictated from the top and there have been all sorts of subtle (and not-so-subtle) changes, many of which I have seen deplored on this board.

The point I'm making is, that whilst it is perfectly true that, in the past, grammar has been the property of the elite, it is now incresingly in the hands of everyone and is being led by pop-stars, sports "personalities", TV presenters, all aided by the media. But it is still grammar, and to be not only understood but thought to be a good commuinicator, you have to keep up with whatever the current rules are.
Those who stand back from this dynamism, throwing up there hands in horror and complaining about "the debasement of the language" are being "snooty and elite", but they are *not the ones who are setting the grammar rules. (and probably aren't very necessary!)