[jboss-cvs] jboss-serialization/src/org/jboss/serial/objectmetamodel ...

Clebert Suconic csuconic at jboss.com
Tue Apr 10 13:21:49 EDT 2007


  User: csuconic
  Date: 07/04/10 13:21:49

  Modified:    src/org/jboss/serial/objectmetamodel  
                        ObjectDescriptorFactory.java ObjectsCache.java
  Log:
  http://jira.jboss.org/jira/browse/JBSER-84 - Implementation of User Based Immutables
  
  Revision  Changes    Path
  1.32      +4 -4      jboss-serialization/src/org/jboss/serial/objectmetamodel/ObjectDescriptorFactory.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ObjectDescriptorFactory.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-serialization/src/org/jboss/serial/objectmetamodel/ObjectDescriptorFactory.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -b -r1.31 -r1.32
  --- ObjectDescriptorFactory.java	10 Jul 2006 16:03:35 -0000	1.31
  +++ ObjectDescriptorFactory.java	10 Apr 2007 17:21:49 -0000	1.32
  @@ -235,7 +235,7 @@
               
           }
   
  -        description = cache.findIdInCacheWrite(obj);
  +        description = cache.findIdInCacheWrite(obj, metaData.isImmutable());
   
           if (description != 0)
           {
  @@ -248,7 +248,7 @@
               return;
           } else
           {
  -        	description = cache.putObjectInCacheWrite(obj);
  +        	description = cache.putObjectInCacheWrite(obj, metaData.isImmutable());
           	if (isDebug)
           	{
           		log.debug("describeObject::a new reference " + description);
  @@ -256,10 +256,10 @@
               outputParent.writeByte(DataContainerConstants.NEWDEF);
               cache.getOutput().addObjectReference(description);
               
  -            int cacheId = cache.findIdInCacheWrite(metaData);
  +            int cacheId = cache.findIdInCacheWrite(metaData, false);
               if (cacheId==0)
               {
  -            	cacheId = cache.putObjectInCacheWrite(metaData);
  +            	cacheId = cache.putObjectInCacheWrite(metaData, false);
               	outputParent.writeByte(DataContainerConstants.NEWDEF);
               	outputParent.addObjectReference(cacheId);
               	StreamingClass.saveStream(metaData,outputParent);
  
  
  
  1.24      +22 -14    jboss-serialization/src/org/jboss/serial/objectmetamodel/ObjectsCache.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ObjectsCache.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-serialization/src/org/jboss/serial/objectmetamodel/ObjectsCache.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -b -r1.23 -r1.24
  --- ObjectsCache.java	9 Apr 2007 23:05:20 -0000	1.23
  +++ ObjectsCache.java	10 Apr 2007 17:21:49 -0000	1.24
  @@ -28,6 +28,7 @@
   import java.io.IOException;
   import java.io.ObjectInput;
   import java.io.ObjectOutput;
  +import java.util.HashMap;
   
   import org.jboss.serial.classmetamodel.ClassResolver;
   import org.jboss.serial.objectmetamodel.safecloning.SafeCloningRepository;
  @@ -41,7 +42,13 @@
   {
   	
   	int objectIdOnCache = 0;
  -	final TObjectIntHashMap objectsImmutableCacheOnWrite = new TObjectIntHashMap(regularHashStrategy);
  +
  +	/**
  +	 * This doesn't need a weakHashMap as this is the temporary object serializable cache. It will be released as soon as the streaming is closed.
  +	 * HashMap<Class, TObjectIntHashMap>
  +	 */
  +	final HashMap immutableCache = new HashMap();
  +
   	final TObjectIntHashMap objectsCacheOnWrite = new TObjectIntHashMap(identityHashStrategy);
   	final TIntObjectHashMap objectsCacheOnRead = new TIntObjectHashMap();
   
  @@ -91,7 +98,7 @@
   		}
       	objectsCacheOnWrite.clear();
       	objectsCacheOnRead.clear();
  -    	objectsImmutableCacheOnWrite.clear();
  +    	immutableCache.clear();
       	objectIdOnCache = 0;
       }
       public ClassLoader getLoader() {
  @@ -129,16 +136,11 @@
   		this.stringBuffer = stringBuffer;
   	}
   
  -	public int findIdInCacheWrite(final Object obj)
  -	{
  -		return findIdInCacheWrite(obj, false);
  -	}
  -
       public int findIdInCacheWrite(final Object obj, boolean immutable)
       {
       	if (immutable)
       	{
  -    		return objectsImmutableCacheOnWrite.get(obj);
  +    		return findProperImmutableCache(obj.getClass()).get(obj);
       	}
       	else
       	{
  @@ -146,6 +148,17 @@
       	}
       }
   
  +    private TObjectIntHashMap findProperImmutableCache(Class clazz)
  +    {
  +    	TObjectIntHashMap properCache = (TObjectIntHashMap)immutableCache.get(clazz);
  +    	if (properCache==null)
  +    	{
  +    		properCache = new TObjectIntHashMap(regularHashStrategy);
  +    		immutableCache.put(clazz,properCache);
  +    	}
  +    	return properCache;
  +    }
  +
       /**
        * @param cacheId
        * @return
  @@ -166,17 +179,12 @@
   	}
       
   
  -    public int putObjectInCacheWrite(final Object obj)
  -    {
  -    	return putObjectInCacheWrite(obj,false);
  -    }
  -
       public int putObjectInCacheWrite(final Object obj, boolean isImmutable)
       {
           objectsCacheOnWrite.put(obj,++objectIdOnCache);
       	if (isImmutable)
       	{
  -    		objectsImmutableCacheOnWrite.put(obj, objectIdOnCache);
  +    		findProperImmutableCache(obj.getClass()).put(obj, objectIdOnCache);
       	}
           return objectIdOnCache;
       }
  
  
  



More information about the jboss-cvs-commits mailing list