194 } |
194 } |
195 |
195 |
196 static char[] decode(Charset cs, byte[] ba, int off, int len) { |
196 static char[] decode(Charset cs, byte[] ba, int off, int len) { |
197 // (1)We never cache the "external" cs, the only benefit of creating |
197 // (1)We never cache the "external" cs, the only benefit of creating |
198 // an additional StringDe/Encoder object to wrap it is to share the |
198 // an additional StringDe/Encoder object to wrap it is to share the |
199 // de/encode() method. These SD/E objects are short-lifed, the young-gen |
199 // de/encode() method. These SD/E objects are short-lived, the young-gen |
200 // gc should be able to take care of them well. But the best approash |
200 // gc should be able to take care of them well. But the best approach |
201 // is still not to generate them if not really necessary. |
201 // is still not to generate them if not really necessary. |
202 // (2)The defensive copy of the input byte/char[] has a big performance |
202 // (2)The defensive copy of the input byte/char[] has a big performance |
203 // impact, as well as the outgoing result byte/char[]. Need to do the |
203 // impact, as well as the outgoing result byte/char[]. Need to do the |
204 // optimization check of (sm==null && classLoader0==null) for both. |
204 // optimization check of (sm==null && classLoader0==null) for both. |
205 // (3)getClass().getClassLoader0() is expensive |
205 // (3)getClass().getClassLoader0() is expensive |
206 // (4)There might be a timing gap in isTrusted setting. getClassLoader0() |
206 // (4)There might be a timing gap in isTrusted setting. getClassLoader0() |
207 // is only chcked (and then isTrusted gets set) when (SM==null). It is |
207 // is only checked (and then isTrusted gets set) when (SM==null). It is |
208 // possible that the SM==null for now but then SM is NOT null later |
208 // possible that the SM==null for now but then SM is NOT null later |
209 // when safeTrim() is invoked...the "safe" way to do is to redundant |
209 // when safeTrim() is invoked...the "safe" way to do is to redundant |
210 // check (... && (isTrusted || SM == null || getClassLoader0())) in trim |
210 // check (... && (isTrusted || SM == null || getClassLoader0())) in trim |
211 // but it then can be argued that the SM is null when the opertaion |
211 // but it then can be argued that the SM is null when the operation |
212 // is started... |
212 // is started... |
213 CharsetDecoder cd = cs.newDecoder(); |
213 CharsetDecoder cd = cs.newDecoder(); |
214 int en = scale(len, cd.maxCharsPerByte()); |
214 int en = scale(len, cd.maxCharsPerByte()); |
215 char[] ca = new char[en]; |
215 char[] ca = new char[en]; |
216 if (len == 0) |
216 if (len == 0) |