From ab0eb4eaa86f8aa8a86fb1cc7557d8cbe0099078 Mon Sep 17 00:00:00 2001 From: Carsten Haubold Date: Thu, 3 Jan 2019 10:38:21 +0100 Subject: [PATCH 01/10] Move CacheType from DiskCachedCellImgOptions to ReadOnlyCachedCellImgOptions --- .../cache/img/DiskCachedCellImgOptions.java | 36 ++----------------- .../img/ReadOnlyCachedCellImgOptions.java | 34 +++++++++++++++++- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/main/java/net/imglib2/cache/img/DiskCachedCellImgOptions.java b/src/main/java/net/imglib2/cache/img/DiskCachedCellImgOptions.java index a73ed56..9a71355 100644 --- a/src/main/java/net/imglib2/cache/img/DiskCachedCellImgOptions.java +++ b/src/main/java/net/imglib2/cache/img/DiskCachedCellImgOptions.java @@ -34,6 +34,7 @@ import net.imglib2.Dirty; import net.imglib2.img.basictypeaccess.AccessFlags; +import net.imglib2.cache.img.ReadOnlyCachedCellImgOptions.CacheType; import net.imglib2.img.cell.CellImgFactory; import net.imglib2.util.Util; @@ -115,40 +116,7 @@ public DiskCachedCellImgOptions numIoThreads( final int numIoThreads ) */ public DiskCachedCellImgOptions maxIoQueueSize( final int maxIoQueueSize ) { - return new DiskCachedCellImgOptions( values.copy().setMaxIoQueueSize( maxIoQueueSize ) ); - } - - /** - * Rough in-memory cache types. - * - * @author Tobias Pietzsch - */ - public static enum CacheType - { - /** - * The cache keeps SoftReferences to values (cells), basically relying - * on GC for removal. The advantage of this is that many caches can be - * created without needing to put a limit on the size of any of them. GC - * will take care of balancing that. The downside is that - * {@link OutOfMemoryError} may occur because {@link SoftReference}s are - * cleared too slow. SoftReferences are not collected for a certain time - * after they have been used. If there is heavy thrashing with cells - * being constantly swapped in and out from disk then OutOfMemory may - * happen because of this. This sounds worse than it is in practice and - * should only happen in pathological situations. Tuning the - * {@code -XX:SoftRefLRUPolicyMSPerMB} JVM flag does often help. - */ - SOFTREF, - - /** - * The cache keeps strong references to a limited number of values - * (cells). The advantage is that there is never OutOfMemory because of - * the issues described above (fingers crossed). The downside is that - * the number of cells that should be cached needs to be specified - * beforehand. So {@link OutOfMemoryError} may occur if many caches are - * opened and consume too much memory in total. - */ - BOUNDED + return new DiskCachedCellImgOptions(values.copy().setMaxIoQueueSize( maxIoQueueSize )); } /** diff --git a/src/main/java/net/imglib2/cache/img/ReadOnlyCachedCellImgOptions.java b/src/main/java/net/imglib2/cache/img/ReadOnlyCachedCellImgOptions.java index d4b10bf..5d82b05 100644 --- a/src/main/java/net/imglib2/cache/img/ReadOnlyCachedCellImgOptions.java +++ b/src/main/java/net/imglib2/cache/img/ReadOnlyCachedCellImgOptions.java @@ -32,7 +32,6 @@ import java.util.Set; import net.imglib2.Dirty; -import net.imglib2.cache.img.DiskCachedCellImgOptions.CacheType; import net.imglib2.img.basictypeaccess.AccessFlags; import net.imglib2.img.cell.CellImgFactory; import net.imglib2.util.Util; @@ -86,6 +85,39 @@ public ReadOnlyCachedCellImgOptions volatileAccesses( final boolean volatil ) return new ReadOnlyCachedCellImgOptions( values.copy().setVolatileAccesses( volatil ) ); } + /** + * Rough in-memory cache types. + * + * @author Tobias Pietzsch + */ + public static enum CacheType + { + /** + * The cache keeps SoftReferences to values (cells), basically relying + * on GC for removal. The advantage of this is that many caches can be + * created without needing to put a limit on the size of any of them. GC + * will take care of balancing that. The downside is that + * {@link OutOfMemoryError} may occur because {@link SoftReference}s are + * cleared too slow. SoftReferences are not collected for a certain time + * after they have been used. If there is heavy thrashing with cells + * being constantly swapped in and out from disk then OutOfMemory may + * happen because of this. This sounds worse than it is in practice and + * should only happen in pathological situations. Tuning the + * {@code -XX:SoftRefLRUPolicyMSPerMB} JVM flag does often help. + */ + SOFTREF, + + /** + * The cache keeps strong references to a limited number of values + * (cells). The advantage is that there is never OutOfMemory because of + * the issues described above (fingers crossed). The downside is that + * the number of cells that should be cached needs to be specified + * beforehand. So {@link OutOfMemoryError} may occur if many caches are + * opened and consume too much memory in total. + */ + BOUNDED + } + /** * Which in-memory cache type to use. The options are *