ObjectIn/OutputStream improvements

Peter Levart peter.levart at gmail.com
Wed Feb 5 16:39:58 UTC 2014

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);
             return appendClassSignature(new StringBuilder(), 

     private static StringBuilder appendClassSignature(StringBuilder 
sbuf, Class<?> cl) {
         while (cl.isArray()) {
             cl = cl.getComponentType();

         if (cl.isPrimitive())
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();
         for (int i = 0; i < paramTypes.length; i++) {
             appendClassSignature(sbuf, paramTypes[i]);
         appendClassSignature(sbuf, retType);
         return sbuf.toString();

Regards, Peter

More information about the core-libs-dev mailing list