8177631: Outdated performance advice in StringCoding

Reviewed-by: sherman
This commit is contained in:
Claes Redestad 2017-04-04 10:53:27 +02:00
parent 330b9195c9
commit 3be6ab78ef

View File

@ -272,8 +272,7 @@ class StringCoding {
// (2)The defensive copy of the input byte/char[] has a big performance // (2)The defensive copy of the input byte/char[] has a big performance
// impact, as well as the outgoing result byte/char[]. Need to do the // impact, as well as the outgoing result byte/char[]. Need to do the
// optimization check of (sm==null && classLoader0==null) for both. // optimization check of (sm==null && classLoader0==null) for both.
// (3)getClass().getClassLoader0() is expensive // (3)There might be a timing gap in isTrusted setting. getClassLoader0()
// (4)There might be a timing gap in isTrusted setting. getClassLoader0()
// is only checked (and then isTrusted gets set) when (SM==null). It is // is only checked (and then isTrusted gets set) when (SM==null). It is
// possible that the SM==null for now but then SM is NOT null later // possible that the SM==null for now but then SM is NOT null later
// when safeTrim() is invoked...the "safe" way to do is to redundant // when safeTrim() is invoked...the "safe" way to do is to redundant
@ -299,8 +298,8 @@ class StringCoding {
if (len == 0) { if (len == 0) {
return new Result().with(); return new Result().with();
} }
if (System.getSecurityManager() != null && if (cs.getClass().getClassLoader0() != null &&
cs.getClass().getClassLoader0() != null) { System.getSecurityManager() != null) {
ba = Arrays.copyOfRange(ba, off, off + len); ba = Arrays.copyOfRange(ba, off, off + len);
off = 0; off = 0;
} }
@ -609,8 +608,8 @@ class StringCoding {
if (len == 0) { if (len == 0) {
return ba; return ba;
} }
boolean isTrusted = System.getSecurityManager() == null || boolean isTrusted = cs.getClass().getClassLoader0() == null ||
cs.getClass().getClassLoader0() == null; System.getSecurityManager() == null;
ce.onMalformedInput(CodingErrorAction.REPLACE) ce.onMalformedInput(CodingErrorAction.REPLACE)
.onUnmappableCharacter(CodingErrorAction.REPLACE) .onUnmappableCharacter(CodingErrorAction.REPLACE)
.reset(); .reset();