ObjectIn/OutputStream improvements
Robert Stupp
snazy at snazy.de
Thu Feb 6 22:50:53 UTC 2014
Hi,
I looked into the UTF serialization and deserialization code - and compared it a bit with the code behind "new String(byte[], Charset)", "String.getBytes(Charset)".
Just to find something that can be safely reused in Object*Stream classes to optimize String handling.
The first thing I noticed is that the class sun.nio.cs.UTF_8 class uses one byte for (char)0 - Object*Stream use two 0 bytes to represent (char)0. Although this representation is incompatible to the representation that the class UTF_8 uses it is not a big issue.
The other thing is that Object*Stream seem not to be able to (de)serialize 21 bit characters. Methods in UTF_8 class are sun.nio.cs.UTF_8.Decoder#decode and sun.nio.cs.UTF_8.Encoder#encode. Is it ok to add 21-bit UTF-8 representation in Object*Stream?
-
Robert
Am 06.02.2014 um 13:07 schrieb Chris Hegarty <chris.hegarty at oracle.com>:
> Thanks Peter, this is a nice improvement. I’ll incorporate your changes before pushing.
>
> -Chris.
>
> On 5 Feb 2014, at 16:39, Peter Levart <peter.levart at gmail.com> wrote:
>
>> On 02/05/2014 04:11 PM, Chris Hegarty wrote:
>>> Thanks stuart, Mike, and Paul.
>>>
>>>> - Why not have getClassSignature() return an interned string? (that's if interning is actually essential. Are we sure it's not just overhead?)
>>> I didn’t want to change the existing use of interning here, just refactor the code a little to make it cleaner.
>>>
>>>> I think that would be a better way to spend our performance investigation budget. Thus, it might be better to remove the StringBuilder field from this patch and submit another one focusing on UTF decoding; the other changes in the patch look good.
>>> Agreed. This could be looked at separately.
>>>
>>> Latest webrev:
>>> http://cr.openjdk.java.net/~chegar/serial_stupp.01/
>>>
>>> Thanks,
>>> -Chris.
>>
>> Hi Chris,
>>
>> What about the following even less garbage-producing-and-copying ObjectStreamClass.get[Class|Method]Signature combo:
>>
>> /**
>> * Returns JVM type signature for given class.
>> */
>> static String getClassSignature(Class<?> cl) {
>> if (cl.isPrimitive())
>> return getPrimitiveSignature(cl);
>> else
>> return appendClassSignature(new StringBuilder(), cl).toString();
>> }
>>
>> private static StringBuilder appendClassSignature(StringBuilder sbuf, Class<?> cl) {
>> while (cl.isArray()) {
>> sbuf.append('[');
>> cl = cl.getComponentType();
>> }
>>
>> if (cl.isPrimitive())
>> sbuf.append(getPrimitiveSignature(cl));
>> else
>> sbuf.append('L').append(cl.getName().replace('.', '/')).append(';');
>>
>> return sbuf;
>> }
>>
>> /**
>> * Returns JVM type signature for given list of parameters and return type.
>> */
>> private static String getMethodSignature(Class<?>[] paramTypes,
>> Class<?> retType)
>> {
>> StringBuilder sbuf = new StringBuilder();
>> sbuf.append('(');
>> for (int i = 0; i < paramTypes.length; i++) {
>> appendClassSignature(sbuf, paramTypes[i]);
>> }
>> sbuf.append(')');
>> appendClassSignature(sbuf, retType);
>> return sbuf.toString();
>> }
>>
>>
>> Regards, Peter
>>
>
More information about the core-libs-dev
mailing list