The broader point that I am making, outside the specific instance of the Japanese which you seem to want to fixate on, is that xenophobia can be a useful social trait, to avoid a society being overwhelmed by a foreign ingress. This could work just as well for the Ainu, the Okinawans and the Koreans (and I'm sure they exhibited it too, but unfortunately weren't in a position to act on it strongly enough to defend against colonisation/vassalisation).