harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r646645 - /harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java
Date Thu, 10 Apr 2008 04:52:47 GMT
Author: varlax
Date: Wed Apr  9 21:52:45 2008
New Revision: 646645

URL: http://svn.apache.org/viewvc?rev=646645&view=rev
Log:
Applied HARMONY-5633 [classlib][luni][performance] ObjectStreamClass lookup improvement

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java?rev=646645&r1=646644&r2=646645&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/ObjectStreamClass.java
Wed Apr  9 21:52:45 2008
@@ -34,6 +34,7 @@
 
 import org.apache.harmony.luni.util.Msg;
 import org.apache.harmony.luni.util.PriviAction;
+import org.apache.harmony.luni.util.ThreadLocalCache;
 
 /**
  * Instances of ObjectStreamClass are used to describe classes of objects used
@@ -135,10 +136,6 @@
 
     static final Class<ObjectStreamClass> OBJECTSTREAMCLASSCLASS = ObjectStreamClass.class;
 
-    // Table mapping instances of java.lang.Class to to corresponding instances
-    // of ObjectStreamClass
-    private static final WeakHashMap<Class<?>, ObjectStreamClass> classesAndDescriptors
= new WeakHashMap<Class<?>, ObjectStreamClass>();
-
     private transient Method methodWriteReplace;
 
     private transient Method methodReadResolve;
@@ -928,15 +925,13 @@
      */
     private static ObjectStreamClass lookupStreamClass(Class<?> cl,
             boolean computeSUID) {
-        // Synchronized because of the lookup table 'classesAndDescriptors'
 
-        ObjectStreamClass cachedValue;
-        synchronized (classesAndDescriptors) {
-            cachedValue = classesAndDescriptors.get(cl);
-            if (cachedValue == null) {
-                cachedValue = createClassDesc(cl, computeSUID);
-                classesAndDescriptors.put(cl, cachedValue);
-            }
+        WeakHashMap<Class<?>,ObjectStreamClass> tlc = OSCThreadLocalCache.oscWeakHashMap.get();
+
+        ObjectStreamClass cachedValue = tlc.get(cl);
+        if (cachedValue == null) {
+            cachedValue = createClassDesc(cl, computeSUID);
+            tlc.put(cl, cachedValue);
         }
         return cachedValue;
 
@@ -1151,4 +1146,16 @@
         return getName() + ": static final long serialVersionUID =" //$NON-NLS-1$
                 + getSerialVersionUID() + "L;"; //$NON-NLS-1$
     }
+
+    static class OSCThreadLocalCache extends ThreadLocalCache {
+
+        // thread-local cache for ObjectStreamClass.lookup
+        public static ThreadLocalCache<WeakHashMap<Class<?>,ObjectStreamClass>>
oscWeakHashMap = new ThreadLocalCache<WeakHashMap<Class<?>,ObjectStreamClass>>()
{
+            protected WeakHashMap<Class<?>,ObjectStreamClass> initialValue()
{
+                return new WeakHashMap<Class<?>,ObjectStreamClass>();
+            }
+        };
+
+    }
+
 }



Mime
View raw message