Uploaded image for project: 'MINA'
  1. MINA
  2. DIRMINA-991

Possible faster deserialization in AbstractIoBuffer object deserialization.

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.8
    • Fix Version/s: 2.0.9
    • Component/s: Core
    • Labels:

      Description

      In ObjectInputStream.resolveClass() of AbstractIoBuffer.getObject() there is a possibility to avoid duplicate call to Class.forName(). First call is done in readClassDescriptor() and second in resolveClass() in case we deal with Serializables, class descriptors are cached by the java platform, and a call of desc.forClass() in resolveClass() returns a previous resolved class, which allows skipping the ClassLoader call. I append the original source and a possible fix for this issue. Is it possible to get this in the upcomming 2.0.9 release of MINA?

      Original source :

      protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
                          String name = desc.getName();
                          try {
                              return Class.forName(name, false, classLoader);
                          } catch (ClassNotFoundException ex) {
                              return super.resolveClass(desc);
                          }
      
      

      Possible fix :

      protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
                          if (null == desc.forClass()) {  //this works for serializable desc classes.
                              String name = desc.getName();
                              try {
                                  return Class.forName(name, false, classLoader);
                              } catch (ClassNotFoundException ex) {
                                  return super.resolveClass(desc);
                              }
                          } else {
                              return desc.forClass();
                          }
                      }
      

        Activity

        Hide
        elecharny Emmanuel Lecharny added a comment -

        Vote for 2.0.9 has been cancelled, this patch (and DIRMINA-990) have been included in 2.0.9 and a new vote has been started.

        Show
        elecharny Emmanuel Lecharny added a comment - Vote for 2.0.9 has been cancelled, this patch (and DIRMINA-990 ) have been included in 2.0.9 and a new vote has been started.
        Hide
        elecharny Emmanuel Lecharny added a comment -

        I may cancel the 2.0.9 vote and get the patch included in a new vote. I'll keep you informed asap.

        Show
        elecharny Emmanuel Lecharny added a comment - I may cancel the 2.0.9 vote and get the patch included in a new vote. I'll keep you informed asap.
        Hide
        elecharny Emmanuel Lecharny added a comment -

        Patch applied with Commit: c1792331521ec1f50e9c71228a20ca4ab21029fa

        Show
        elecharny Emmanuel Lecharny added a comment - Patch applied with Commit: c1792331521ec1f50e9c71228a20ca4ab21029fa
        Hide
        j.michelberger Jörg Michelberger added a comment -

        Great, no duplicate desc.forClass() call. Looking forward to 2.0.10.

        Show
        j.michelberger Jörg Michelberger added a comment - Great, no duplicate desc.forClass() call. Looking forward to 2.0.10.
        Hide
        elecharny Emmanuel Lecharny added a comment -

        As for DIRMINA-990, MINA 2.0.9 is already been vote, it's a bit too late to get this fix included in the package. I'll apply the proposed patch in 2.0.10, which should be out soon.

        Here is the code after the patch :

                        protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
                            Class<?> clazz = desc.forClass();
                            
                            if (clazz == null) {
                                String name = desc.getName();
                                try {
                                    return Class.forName(name, false, classLoader);
                                } catch (ClassNotFoundException ex) {
                                    return super.resolveClass(desc);
                                }
                            } else {
                                return clazz;
                            }
                        }
        
        Show
        elecharny Emmanuel Lecharny added a comment - As for DIRMINA-990 , MINA 2.0.9 is already been vote, it's a bit too late to get this fix included in the package. I'll apply the proposed patch in 2.0.10, which should be out soon. Here is the code after the patch : protected Class <?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { Class <?> clazz = desc.forClass(); if (clazz == null ) { String name = desc.getName(); try { return Class .forName(name, false , classLoader); } catch (ClassNotFoundException ex) { return super .resolveClass(desc); } } else { return clazz; } }

          People

          • Assignee:
            Unassigned
            Reporter:
            j.michelberger Jörg Michelberger
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development