Revision: 9538
Author: [email protected]
Date: Thu Jan 13 09:40:26 2011
Log: Cache ModuleDefs by context ClassLoader.
GWT Designer need separated class loader for every open project.
http://gwt-code-reviews.appspot.com/1274801/show
Patch by: amitin
Review by: me,zundel
http://code.google.com/p/google-web-toolkit/source/detail?r=9538
Modified:
/trunk/dev/core/src/com/google/gwt/dev/cfg/ModuleDefLoader.java
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/cfg/ModuleDefLoader.java Fri
Jan 7 11:13:03 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/cfg/ModuleDefLoader.java Thu Jan
13 09:40:26 2011
@@ -40,6 +40,9 @@
* The top-level API for loading module XML.
*/
public final class ModuleDefLoader {
+ /*
+ * TODO(scottb,tobyr,zundel): synchronization????
+ */
/**
* Interface to provide a load strategy to the load process.
@@ -64,11 +67,12 @@
/**
* Keep soft references to loaded modules so the VM can gc them when
memory is
- * tight. The module's physical name is used as a key.
+ * tight. The current context class loader used as a key for modules
cache.
+ * The module's physical name is used as a key inside the cache.
*/
@SuppressWarnings("unchecked")
- private static final Map<String, ModuleDef> loadedModules = new
ReferenceMap(
- AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT);
+ private static final Map<ClassLoader, Map<String, ModuleDef>>
loadedModulesCaches = new ReferenceMap(
+ AbstractReferenceMap.WEAK, AbstractReferenceMap.HARD);
/**
* A mapping from effective to physical module names.
@@ -150,8 +154,19 @@
}
}
+ @SuppressWarnings("unchecked")
+ private static Map<String, ModuleDef> getModulesCache() {
+ ClassLoader keyClassLoader =
Thread.currentThread().getContextClassLoader();
+ Map<String, ModuleDef> cache = loadedModulesCaches.get(keyClassLoader);
+ if (cache == null) {
+ cache = new ReferenceMap(AbstractReferenceMap.HARD,
AbstractReferenceMap.SOFT);
+ loadedModulesCaches.put(keyClassLoader, cache);
+ }
+ return cache;
+ }
+
private static ModuleDef tryGetLoadedModule(String moduleName, boolean
refresh) {
- ModuleDef moduleDef = loadedModules.get(moduleName);
+ ModuleDef moduleDef = getModulesCache().get(moduleName);
if (moduleDef == null || moduleDef.isGwtXmlFileStale()) {
return null;
} else if (refresh) {
@@ -301,7 +316,7 @@
moduleNormalizeEvent.end();
// Add the "physical" module name: com.google.Module
- loadedModules.put(moduleName, moduleDef);
+ getModulesCache().put(moduleName, moduleDef);
// Add a mapping from the module's effective name to its physical name
moduleEffectiveNameToPhysicalName.put(moduleDef.getName(), moduleName);
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors