ObjectIn/OutputStream improvements
Chris Hegarty
chris.hegarty at oracle.com
Thu Feb 6 12:07:37 UTC 2014
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