diff options
author | Shawn O. Pearce <spearce@spearce.org> | 2010-08-31 13:13:28 -0700 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2010-09-02 11:38:39 -0700 |
commit | e29cd27961856376184edc74df700629003ad2f0 (patch) | |
tree | 8df495d3274e0b5296ae61bef7e1b6b4b735240c /org.eclipse.jgit | |
parent | fed508d55b8dcc3b9a3318b289e3eaaadd3ecb29 (diff) | |
download | jgit-e29cd27961856376184edc74df700629003ad2f0.tar.gz jgit-e29cd27961856376184edc74df700629003ad2f0.zip |
Move ObjectDirectory streaming limit to WindowCacheConfig
IDEs like Eclipse offer up the settings in WindowCacheConfig to the
user as a global set of options that are configured for the entire
JVM process, not per-repository, as the cache is shared across the
entire JVM. The limit on how much we are willing to allocate for
an object buffer is similar to the limit on how much we can use for
data caches, allocating that much space impacts the entire JVM and
not just a single repository, so it should be a global limit.
Change-Id: I22eafb3e223bf8dea57ece82cd5df8bfe5badebc
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'org.eclipse.jgit')
7 files changed, 35 insertions, 30 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/CachedObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/CachedObjectDirectory.java index bac8e7b427..ca0f06fae1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/CachedObjectDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/CachedObjectDirectory.java @@ -218,9 +218,4 @@ class CachedObjectDirectory extends FileObjectDatabase { WindowCursor curs) throws IOException { wrapped.selectObjectRepresentation(packer, otp, curs); } - - @Override - int getStreamFileThreshold() { - return wrapped.getStreamFileThreshold(); - } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileObjectDatabase.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileObjectDatabase.java index cb1fdb6240..da38887fc6 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileObjectDatabase.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileObjectDatabase.java @@ -248,8 +248,6 @@ abstract class FileObjectDatabase extends ObjectDatabase { abstract FileObjectDatabase newCachedFileObjectDatabase(); - abstract int getStreamFileThreshold(); - static class AlternateHandle { final FileObjectDatabase db; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java index 1452248070..66e7ebc015 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileRepository.java @@ -170,7 +170,6 @@ public class FileRepository extends Repository { options.getObjectDirectory(), // options.getAlternateObjectDirectories(), // getFS()); - getListenerList().addConfigChangedListener(objectDatabase); if (objectDatabase.exists()) { final String repositoryFormatVersion = getConfig().getString( diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java index 76fbe6e2d0..2ad14c804a 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/ObjectDirectory.java @@ -63,13 +63,10 @@ import java.util.concurrent.atomic.AtomicReference; import org.eclipse.jgit.JGitText; import org.eclipse.jgit.errors.PackMismatchException; -import org.eclipse.jgit.events.ConfigChangedEvent; -import org.eclipse.jgit.events.ConfigChangedListener; import org.eclipse.jgit.lib.AbbreviatedObjectId; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.lib.Constants; -import org.eclipse.jgit.lib.CoreConfig; import org.eclipse.jgit.lib.ObjectDatabase; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectInserter; @@ -98,8 +95,7 @@ import org.eclipse.jgit.util.FS; * searched (recursively through all alternates) before the slow half is * considered. */ -public class ObjectDirectory extends FileObjectDatabase implements - ConfigChangedListener { +public class ObjectDirectory extends FileObjectDatabase { private static final PackList NO_PACKS = new PackList(-1, -1, new PackFile[0]); /** Maximum number of candidates offered as resolutions of abbreviation. */ @@ -121,8 +117,6 @@ public class ObjectDirectory extends FileObjectDatabase implements private final AtomicReference<AlternateHandle[]> alternates; - private int streamFileThreshold; - /** * Initialize a reference to an on-disk object directory. * @@ -157,13 +151,6 @@ public class ObjectDirectory extends FileObjectDatabase implements alt[i] = openAlternate(alternatePaths[i]); alternates.set(alt); } - - onConfigChanged(new ConfigChangedEvent()); - } - - public void onConfigChanged(ConfigChangedEvent event) { - CoreConfig core = config.get(CoreConfig.KEY); - streamFileThreshold = core.getStreamFileThreshold(); } /** @@ -744,9 +731,4 @@ public class ObjectDirectory extends FileObjectDatabase implements FileObjectDatabase newCachedFileObjectDatabase() { return new CachedObjectDirectory(this); } - - @Override - int getStreamFileThreshold() { - return streamFileThreshold; - } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCache.java index 39633ee5ef..523e084845 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCache.java @@ -133,6 +133,8 @@ public class WindowCache { private static volatile WindowCache cache; + private static volatile int streamFileThreshold; + static { reconfigure(new WindowCacheConfig()); } @@ -184,9 +186,14 @@ public class WindowCache { if (oc != null) oc.removeAll(); cache = nc; + streamFileThreshold = cfg.getStreamFileThreshold(); UnpackedObjectCache.reconfigure(cfg); } + static int getStreamFileThreshold() { + return streamFileThreshold; + } + static WindowCache getInstance() { return cache; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheConfig.java index 48d7018e42..90ea376b5f 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCacheConfig.java @@ -44,6 +44,7 @@ package org.eclipse.jgit.storage.file; import org.eclipse.jgit.lib.Config; +import org.eclipse.jgit.lib.ObjectLoader; /** Configuration parameters for {@link WindowCache}. */ public class WindowCacheConfig { @@ -63,6 +64,8 @@ public class WindowCacheConfig { private int deltaBaseCacheLimit; + private int streamFileThreshold; + /** Create a default configuration. */ public WindowCacheConfig() { packedGitOpenFiles = 128; @@ -70,6 +73,7 @@ public class WindowCacheConfig { packedGitWindowSize = 8 * KB; packedGitMMAP = false; deltaBaseCacheLimit = 10 * MB; + streamFileThreshold = ObjectLoader.STREAM_THRESHOLD; } /** @@ -160,6 +164,22 @@ public class WindowCacheConfig { deltaBaseCacheLimit = newLimit; } + /** @return the size threshold beyond which objects must be streamed. */ + public int getStreamFileThreshold() { + return streamFileThreshold; + } + + /** + * @param newLimit + * new byte limit for objects that must be streamed. Objects + * smaller than this size can be obtained as a contiguous byte + * array, while objects bigger than this size require using an + * {@link org.eclipse.jgit.lib.ObjectStream}. + */ + public void setStreamFileThreshold(final int newLimit) { + streamFileThreshold = newLimit; + } + /** * Update properties by setting fields from the configuration. * <p> @@ -174,5 +194,11 @@ public class WindowCacheConfig { setPackedGitWindowSize(rc.getInt("core", null, "packedgitwindowsize", getPackedGitWindowSize())); setPackedGitMMAP(rc.getBoolean("core", null, "packedgitmmap", isPackedGitMMAP())); setDeltaBaseCacheLimit(rc.getInt("core", null, "deltabasecachelimit", getDeltaBaseCacheLimit())); + + long maxMem = Runtime.getRuntime().maxMemory(); + long sft = rc.getLong("core", null, "streamfilethreshold", getStreamFileThreshold()); + sft = Math.min(sft, maxMem / 4); // don't use more than 1/4 of the heap + sft = Math.min(sft, Integer.MAX_VALUE); // cannot exceed array length + setStreamFileThreshold((int) sft); } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCursor.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCursor.java index 09db49e8f8..8679c0de10 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCursor.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/WindowCursor.java @@ -267,9 +267,7 @@ final class WindowCursor extends ObjectReader implements ObjectReuseAsIs { } int getStreamFileThreshold() { - if (db == null) - return ObjectLoader.STREAM_THRESHOLD; - return db.getStreamFileThreshold(); + return WindowCache.getStreamFileThreshold(); } /** Release the current window cursor. */ |