X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FQueryCollectorImpl2.java;h=b0e6330700e2fd587d9aa873a0446671ddd1f77d;hp=0c33321731053d96c7f8c5bcf6c47deac66ba809;hb=HEAD;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07 diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCollectorImpl2.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCollectorImpl2.java index 0c3332173..b0e633070 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCollectorImpl2.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/QueryCollectorImpl2.java @@ -6,9 +6,10 @@ import java.util.IdentityHashMap; import java.util.List; import java.util.Map; +import org.simantics.databoard.Bindings; import org.simantics.databoard.util.IdentityHashSet; +import org.simantics.db.DevelopmentKeys; import org.simantics.db.common.exception.DebugException; -import org.simantics.db.impl.DebugPolicy; import org.simantics.db.impl.query.QueryProcessor.QueryCollectorSupport; import org.simantics.utils.Development; @@ -25,24 +26,32 @@ class QueryCollectorImpl2 implements QueryProcessor.QueryCollector { this.support = support; } - private boolean findCollectables(CacheEntry entry, Map collectables, ArrayList result) { + private boolean findCollectables(CacheEntry entry, Map collectables, ArrayList result) { if (entry.isDiscarded()) { - if(DebugPolicy.COLLECT && DebugPolicy.VERBOSE) - System.out.println("GC: discarded entry " + entry); + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYCOLLECTOR, Bindings.BOOLEAN)) { + System.err.println("GC: discarded entry " + entry); + } + } return true; } if (entry.isPending()) { - if(DebugPolicy.COLLECT && DebugPolicy.VERBOSE) - System.out.println("GC: pending entry " + entry + " was not collected."); + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYCOLLECTOR, Bindings.BOOLEAN)) { + System.err.println("GC: pending entry " + entry + " was not collected."); + } + } collectables.remove(entry); return false; } - if (this.queryProcessor.hasListenerAfterDisposing(entry)) { - if (DebugPolicy.COLLECT && DebugPolicy.VERBOSE) { - System.out.println("GC: listened entry " + entry + " was not collected. Entry=" + entry); + if (this.queryProcessor.listening.hasListenerAfterDisposing(entry)) { + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYCOLLECTOR, Bindings.BOOLEAN)) { + System.err.println("GC: listened entry " + entry + " was not collected. Entry=" + entry); + } } collectables.remove(entry); return false; @@ -60,8 +69,11 @@ class QueryCollectorImpl2 implements QueryProcessor.QueryCollector { } if(!parentIsCollectable) { - if(DebugPolicy.COLLECT && DebugPolicy.VERBOSE) - System.out.println("GC: due to bound parent " + parent + " the entry + " + entry + " was not collected."); + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYCOLLECTOR, Bindings.BOOLEAN)) { + System.err.println("GC: due to bound parent " + parent + " the entry + " + entry + " was not collected."); + } + } collectables.remove(entry); return false; } @@ -109,8 +121,11 @@ class QueryCollectorImpl2 implements QueryProcessor.QueryCollector { // Compute amount of free queries int freeCount = collectables.size(); - if(DebugPolicy.COLLECT) - System.out.println("collector found " + freeCount + " free queries."); + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYCOLLECTOR, Bindings.BOOLEAN)) { + System.err.println("collector found " + freeCount + " free queries."); + } + } lastKnownFixedSize = currentSize - freeCount; @@ -119,8 +134,13 @@ class QueryCollectorImpl2 implements QueryProcessor.QueryCollector { int target = freeCount - maxNumberOfCollectableQueries/2; - if(DebugPolicy.COLLECT) - System.out.println("collector removes " + target + " free queries."); + + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYCOLLECTOR, Bindings.BOOLEAN)) { + System.err.println("collector found " + freeCount + " free queries."); + System.err.println("collector removes " + target + " free queries."); + } + } for(CacheEntry entry : collectables) { if(queryProcessor.removeQuery(entry)) @@ -129,7 +149,7 @@ class QueryCollectorImpl2 implements QueryProcessor.QueryCollector { // Prune discarded parents ArrayList removals = new ArrayList(); - for (CacheEntry entry : support.allCaches().toCollection()) { + for (CacheEntry entry : support.allCaches().toCollection()) { for(CacheEntry p : entry.getParents(queryProcessor)) { if(p.isDiscarded()) removals.add(p); } @@ -139,8 +159,11 @@ class QueryCollectorImpl2 implements QueryProcessor.QueryCollector { removals.clear(); } - if(DebugPolicy.COLLECT) { - System.out.println("collect found " + freeCount + " collectable entries."); + + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYCOLLECTOR, Bindings.BOOLEAN)) { + System.err.println("collect found " + freeCount + " collectable entries."); + } } return; @@ -152,31 +175,40 @@ class QueryCollectorImpl2 implements QueryProcessor.QueryCollector { try { - int current = support.calculateCurrentSize(); - if(DebugPolicy.COLLECT) - new DebugException("checking the need for collecting queries (current=" + current + " , lastKnownFixedSize=" + lastKnownFixedSize + " max free=" + 0 + ")").printStackTrace(); + int current = support.calculateCurrentSize(); - QueryProcessor.collecting = true; + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYCOLLECTOR, Bindings.BOOLEAN)) { + new DebugException("checking the need for collecting queries (current=" + current + " , lastKnownFixedSize=" + lastKnownFixedSize + " max free=" + 0 + ")").printStackTrace(); + } + } + + queryProcessor.cache.collecting = true; long start = System.nanoTime(); doCollect(current, 0); - if(DebugPolicy.COLLECT) - System.out.println("collect finished with " + support.calculateCurrentSize() + " entries (lastKnownFixedSize=" + lastKnownFixedSize + ")."); + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYCOLLECTOR, Bindings.BOOLEAN)) { + System.err.println("collect finished with " + support.calculateCurrentSize() + " entries (lastKnownFixedSize=" + lastKnownFixedSize + ")."); + } + } long duration = System.nanoTime() - start; - if(DebugPolicy.COLLECT) - System.err.println("Collect took " + 1e-9*duration + "s."); + if (Development.DEVELOPMENT) { + if(Development.getProperty(DevelopmentKeys.QUERYCOLLECTOR, Bindings.BOOLEAN)) { + System.err.println("Collect took " + 1e-9*duration + "s."); + } + } } catch (Throwable t) { t.printStackTrace(); } - QueryProcessor.collecting = false; - + queryProcessor.cache.collecting = false; }