4 Replies Latest reply on Nov 1, 2005 11:41 PM by Scott Stark

    SafeToClone operations and SafeToCache operations

    Clebert Suconic Master

      *SafeToClone:* http://jira.jboss.org/jira/browse/JBSER-33

      I just implemented a feature on JBossSerialization useful for cloning operations.

      Say if you are cloning a Proxy, to guarantee classLoading operations you need to find the interfaces on the new ClassLoader and reuse the ClientContainer used inside the proxy.

      The way I was doing that cloning operation before, I was introspecting every single final field on ClientContainer and reusing then. Now, through an interface that I?m calling SafeToClone, we will be able to simply reuse the entire ClientContainer:


      org.jboss.invocation.InvokerInterceptor will be then like this:

      mv = new LocalMarshalledValue(rtnValue,new SafeCloningRepository(new SafeClone(){
      public boolean isSafeToReuse(Object obj) {
      if (obj==null)
      {
      return false;
      }

      if (obj instanceof ClientContainer)
      {
      return true;
      }
      else
      {
      return false;
      }
      }
      }));



      LocalMarshalledValue is a MarshalledValue for JbossSerialization, and a SafeClone interface responsible for intercepting if an object is safe to reuse or not.


      *SafeToCache:*

      And that gave an idea.


      If we could guarantee that ClientContainer was always unique by some primary-key, some UUID, some InvocationContext, whatever, we could cache the interception of ClientContainer somehow and save a lot of CPU for transferring objects.

      I have talked to Scott and Adrian during JBoss World Barcelona and I wasn?t sure about how to implement that feature. But now I think we could actually send the streaming and have the parsing cached on both sides, and only necessarily read it for the first time using some sort of UUID.

      For taking advantage of that feature, we would need ClientContainer in some kind of caching based on the parameters used, instead of create it every time.



      I would create an interface like that, where objects like ClientContainer would be able to implement it:


      public interface SafeToCache
      {
      public String getUUID();
      }



      Of course we will need to find a UUID routine to use here, but I think that will be the easiest part.



      Actually, that idea (caching parsed state) could be used to any reflection like framework, maybe on XML processing as well. (just wondering)





      *SafeToClone* is already implemented (http://jira.jboss.org/jira/browse/JBSER-33) while *SafeToCache* for now is just an idea I wanted to brain storm.

        • 1. Re: SafeToClone operations and SafeToCache operations
          Scott Stark Master

          I'm not clear about the scope of the objects when you say something like ClientContainer is safe to clone, and now cache. There are parts of the ClientContainer such as the InvocationContext content and Interceptors that are not obviously cloneable in general as scoped deployment A could be calling into scoped deployment B using call-by-value where custom interceptors and context coming from the scoped deployment is used, and this would have to be marshalled.

          I don't like the use of a static mapping of the cloneability of a class being in the interceptor. What is needed is a notion of the domain of a type and optional metadata to indicate whether its immutable. If in a call between A and B, type T exists at the same type domain(ClassLoader), it can be cloned. If its also immutable with respect to the call interaction, it can be cached. This seems to need more hotspot like profiling to identify classes marshalled between the same type domain + metadata to mark classes as immutable.

          • 2. Re: SafeToClone operations and SafeToCache operations
            Clebert Suconic Master

            For now, the only thing I'm doing is to reuse ClientContainer when copying the Proxy between classloaders. (Call-by-value on home.create operations)

            What I was talking about caching ClientContainer was just an idea if it would be possible to have some sort of cached stated on expensive objects (from the point of view of serialization/reflection) what would make the streaming faster.


            This is just a generatl idea. I was not planning to implement anything related to ClientContainer now. I was just wondering what classes would take advantage of such feature.

            • 3. Re: SafeToClone operations and SafeToCache operations
              Clebert Suconic Master

              Just making that clear,

              on this implementation, on the serialization of the Proxy, everything will be serialized in VM.

              But on ClientContainer we will be doing a simply setting reference from the original value to the new value.



              The idea for caching serializable states of cerains objects is the same idea of passing Immutable objects over the VM.

              • 4. Re: SafeToClone operations and SafeToCache operations
                Scott Stark Master

                Its a good idea, I would just like to see this implemented in a more flexible fashion. If a set of classes that when seen to exist at the same type domain between caller/callee could be determined dynamically and subsequently cloned, that would be ideal.