Revision: 9512
Author: [email protected]
Date: Fri Jan 7 09:43:50 2011
Log: Pre-initialize ResourceOracleImpl's classpaths in parallel with other
startup
tasks.
http://gwt-code-reviews.appspot.com/1265801/show
Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=9512
Modified:
/trunk/dev/core/src/com/google/gwt/dev/DevMode.java
/trunk/dev/core/src/com/google/gwt/dev/resource/impl/ResourceOracleImpl.java
/trunk/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileClassPathEntry.java
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/DevMode.java Thu Oct 28 11:37:15
2010
+++ /trunk/dev/core/src/com/google/gwt/dev/DevMode.java Fri Jan 7 09:43:50
2011
@@ -23,6 +23,7 @@
import com.google.gwt.core.ext.linker.EmittedArtifact.Visibility;
import com.google.gwt.core.ext.linker.impl.StandardLinkerContext;
import com.google.gwt.dev.cfg.ModuleDef;
+import com.google.gwt.dev.resource.impl.ResourceOracleImpl;
import com.google.gwt.dev.shell.jetty.JettyLauncher;
import com.google.gwt.dev.ui.RestartServerCallback;
import com.google.gwt.dev.ui.RestartServerEvent;
@@ -410,6 +411,21 @@
return true;
}
+ @Override
+ protected boolean doStartup() {
+ // Background scan the classpath to warm the cache.
+ Thread scanThread = new Thread(new Runnable() {
+ public void run() {
+ ResourceOracleImpl.preload(getTopLogger());
+ }
+ });
+ scanThread.setDaemon(true);
+ scanThread.setPriority((Thread.MIN_PRIORITY + Thread.NORM_PRIORITY) /
2);
+ scanThread.start();
+
+ return super.doStartup();
+ }
+
@Override
protected int doStartUpServer() {
// Create the war directory if it doesn't exist
=======================================
---
/trunk/dev/core/src/com/google/gwt/dev/resource/impl/ResourceOracleImpl.java
Tue Oct 12 11:13:43 2010
+++
/trunk/dev/core/src/com/google/gwt/dev/resource/impl/ResourceOracleImpl.java
Fri Jan 7 09:43:50 2011
@@ -170,6 +170,30 @@
return null;
}
}
+
+ /**
+ * Preinitializes the classpath from the thread default {...@link
ClassLoader}.
+ */
+ public static void preload(TreeLogger logger) {
+ preload(logger, Thread.currentThread().getContextClassLoader());
+ }
+
+ /**
+ * Preinitializes the classpath for a given {...@link ClassLoader}.
+ */
+ public static void preload(TreeLogger logger, ClassLoader classLoader) {
+ Event resourceOracle = SpeedTracerLogger.start(
+ CompilerEventType.RESOURCE_ORACLE, "phase", "preload");
+ List<ClassPathEntry> entries = getAllClassPathEntries(logger,
classLoader);
+ for (ClassPathEntry entry : entries) {
+ // We only handle pre-indexing jars, the file system could change.
+ if (entry instanceof ZipFileClassPathEntry) {
+ ZipFileClassPathEntry zpe = (ZipFileClassPathEntry) entry;
+ zpe.index(logger);
+ }
+ }
+ resourceOracle.end();
+ }
/**
* Rescans the associated paths to recompute the available resources.
=======================================
---
/trunk/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileClassPathEntry.java
Wed Aug 4 09:54:49 2010
+++
/trunk/dev/core/src/com/google/gwt/dev/resource/impl/ZipFileClassPathEntry.java
Fri Jan 7 09:43:50 2011
@@ -90,11 +90,7 @@
@Override
public Map<AbstractResource, PathPrefix> findApplicableResources(
TreeLogger logger, PathPrefixSet pathPrefixSet) {
- // Never re-index.
- if (allZipFileResources == null) {
- allZipFileResources = buildIndex(logger);
- }
-
+ index(logger);
ZipFileSnapshot snapshot = cachedSnapshots.get(pathPrefixSet);
if (snapshot == null || snapshot.prefixSetSize !=
pathPrefixSet.getSize()) {
snapshot = new ZipFileSnapshot(pathPrefixSet.getSize(),
@@ -112,6 +108,13 @@
public ZipFile getZipFile() {
return zipFile;
}
+
+ synchronized void index(TreeLogger logger) {
+ // Never re-index.
+ if (allZipFileResources == null) {
+ allZipFileResources = buildIndex(logger);
+ }
+ }
private Set<ZipFileResource> buildIndex(TreeLogger logger) {
logger = Messages.BUILDING_INDEX.branch(logger, zipFile.getName(),
null);
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors