Charset: Fix broken level-1 caching.

The level-1 cache was incorrectly implemented. The check written here :

  if (cache1 != null && charsetName.equals(cache1.getKey()))
      return cache1.getValue();

Is incorrect because a different thread might change the value of cache1
between the null check, the call to getKey and the call to getValue.

The stress test in this change results in a 100% reproducible failure on a
nexus 6P without the included fix.

bug: 26548702

(cherry picked from commit 13a83b88fb12356b6edcb0bdf9171315d80583c0)

Change-Id: I081869f21e9451c03c89b7967c7f779c0205ab95
2 files changed