I've noted elsewhere that serial communications from the M4 to (C in my case) are a little fraught. However, I have found that things return to pretty much normal when X is shut down. Some "back of the packet" calculations suggest the problems gets worse (far, far worse) as the load on the CPU increases. Which reminded me of a bug in something I wrote (cough cough) years ago on a 68000 CPU. In that case it was an interrupt service routine (written in assembler) that simply wasn't quite fast enough. Every so often an interrupt would interrupt it and break my code. Solution in that case (as with all ISRs, really) is to disable all maskable interrupts while you do your work. This smacks of something very similar - I could be wrong of course - but the higher the load (X, Java, etc.) the more likely the serial communication is to drop parts of its buffer.