hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cdoug...@apache.org
Subject svn commit: r812285 - in /hadoop/common/trunk: CHANGES.txt src/java/org/apache/hadoop/conf/Configuration.java
Date Mon, 07 Sep 2009 21:54:46 GMT
Author: cdouglas
Date: Mon Sep  7 21:54:45 2009
New Revision: 812285

URL: http://svn.apache.org/viewvc?rev=812285&view=rev
Log:
HADOOP-6133. Add a caching layer to Configuration::getClassByName to
alleviate a performance regression introduced in a compatibility layer.
Contributed by Todd Lipcon

Modified:
    hadoop/common/trunk/CHANGES.txt
    hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java

Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=812285&r1=812284&r2=812285&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Mon Sep  7 21:54:45 2009
@@ -512,7 +512,8 @@
     HADOOP-6176. Add a couple package private methods to AccessTokenHandler
     for testing.  (Kan Zhang via szetszwo)
 
-    HADOOP-6182. Fix ReleaseAudit warnings (Giridharan Kesavan and Lee Tucker via gkesavan)
+    HADOOP-6182. Fix ReleaseAudit warnings (Giridharan Kesavan and Lee Tucker
+    via gkesavan)
 
     HADOOP-6173. Change src/native/packageNativeHadoop.sh to package all
     native library files.  (Hong Tang via szetszwo)
@@ -526,6 +527,10 @@
     HADOOP-6231. Allow caching of filesystem instances to be disabled on a
     per-instance basis. (tomwhite)
 
+    HADOOP-6133. Add a caching layer to Configuration::getClassByName to
+    alleviate a performance regression introduced in a compatibility layer.
+    (Todd Lipcon via cdouglas)
+
   OPTIMIZATIONS
 
     HADOOP-5595. NameNode does not need to run a replicator to choose a

Modified: hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java?rev=812285&r1=812284&r2=812285&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/conf/Configuration.java Mon Sep  7 21:54:45
2009
@@ -170,6 +170,9 @@
    */
   private static final ArrayList<String> defaultResources = 
     new ArrayList<String>();
+
+  private static final Map<ClassLoader, Map<String, Class<?>>>
+    CACHE_CLASSES = new WeakHashMap<ClassLoader, Map<String, Class<?>>>();
   
   /**
    * Flag to indicate if the storage of resource which updates a key needs 
@@ -1029,7 +1032,27 @@
    * @throws ClassNotFoundException if the class is not found.
    */
   public Class<?> getClassByName(String name) throws ClassNotFoundException {
-    return Class.forName(name, true, classLoader);
+    Map<String, Class<?>> map;
+    
+    synchronized (CACHE_CLASSES) {
+      map = CACHE_CLASSES.get(classLoader);
+      if (map == null) {
+        map = Collections.synchronizedMap(
+          new WeakHashMap<String, Class<?>>());
+        CACHE_CLASSES.put(classLoader, map);
+      }
+    }
+
+    Class clazz = map.get(name);
+    if (clazz == null) {
+      clazz = Class.forName(name, true, classLoader);
+      if (clazz != null) {
+        // two putters can race here, but they'll put the same class
+        map.put(name, clazz);
+      }
+    }
+
+    return clazz;
   }
 
   /** 



Mime
View raw message