Fix error starting up in DevMode+GAE

262 views
Skip to first unread message

ri...@google.com

unread,
Nov 17, 2009, 12:42:26 PM11/17/09
to j...@google.com, sco...@google.com, google-web-tool...@googlegroups.com
Reviewers: jat, scottb,

Description:
If a GC occurs during startup, the AbstractReferenceMap that maps from
the module name to its ModuleDef in ModuleDefLoader can be cleared.
When we attempt to reload the module, we cannot because we only have the
module's "effective name" (i.e., a short, lower-case name), whereas we
need its physical name (i.e., a fully-qualified class name) to perform
the load. This patch creates a separate effective-to-physical name
mapping so even if we lose the ModuleDef we retain the ability to reload
it based on the effective name.

Please review this at http://gwt-code-reviews.appspot.com/103801

Affected files:
dev/core/src/com/google/gwt/dev/cfg/ModuleDefLoader.java


Index: dev/core/src/com/google/gwt/dev/cfg/ModuleDefLoader.java
===================================================================
--- dev/core/src/com/google/gwt/dev/cfg/ModuleDefLoader.java (revision 6955)
+++ dev/core/src/com/google/gwt/dev/cfg/ModuleDefLoader.java (working copy)
@@ -28,6 +28,7 @@
import java.io.Reader;
import java.net.URISyntaxException;
import java.net.URL;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@@ -60,11 +61,17 @@

/**
* Keep soft references to loaded modules so the VM can gc them when
memory is
- * tight.
+ * tight. The module's physical name is used as a key.
*/
@SuppressWarnings("unchecked")
private static final Map<String, ModuleDef> loadedModules = new
ReferenceMap(
AbstractReferenceMap.HARD, AbstractReferenceMap.SOFT);
+
+ /**
+ * A mapping from effective to physical module names.
+ */
+ private static final Map<String, String>
moduleEffectiveNameToPhysicalName =
+ new HashMap<String,String>();

/**
* Creates a module in memory that is not associated with a
@@ -119,6 +126,12 @@
*/
public static ModuleDef loadFromClassPath(TreeLogger logger,
String moduleName, boolean refresh) throws UnableToCompleteException
{
+ // Look up the module's physical name; if null, we are either
encountering
+ // the module for the first time, or else the name is already physical
+ String physicalName =
moduleEffectiveNameToPhysicalName.get(moduleName);
+ if (physicalName != null) {
+ moduleName = physicalName;
+ }
ModuleDef moduleDef = tryGetLoadedModule(logger, moduleName, refresh);
if (moduleDef != null) {
return moduleDef;
@@ -275,8 +288,8 @@
// Add the "physical" module name: com.google.Module
loadedModules.put(moduleName, moduleDef);

- // Add the module's effective name: some.other.Module
- loadedModules.put(moduleDef.getName(), moduleDef);
+ // Add a maping from the module's effective name to its physical name
+ moduleEffectiveNameToPhysicalName.put(moduleDef.getName(), moduleName);
return moduleDef;
}
}


j...@google.com

unread,
Nov 17, 2009, 2:03:26 PM11/17/09
to ri...@google.com, sco...@google.com, google-web-tool...@googlegroups.com
As discussed FTF, I think a better plan is to pin the loaded modules in
memory until they have been referenced at least once from a browser.

Letting them be immediately unloaded before they are used and then
reloading them seems inefficient and will annoy the user with duplicate
warnings/errors from the module load.

The downside of this approach is that any modules which are loaded but
never referenced (such as from a launch config that is used for many
different modules) will pin those modules in memory indefinitely, but I
think that is the lesser evil.


http://gwt-code-reviews.appspot.com/103801

todd....@gmail.com

unread,
Nov 25, 2009, 1:40:18 PM11/25/09
to Google Web Toolkit Contributors
I am experiencing the "Unable to find 'myapp.gwt.xml' on your
classpath; could be a typo, or maybe you forgot to include a classpath
entry for source?" after upgrading to RC1. The project does not use
GAE. Is it possible that this could be same?
Reply all
Reply to author
Forward
0 new messages