Updated Branches: refs/heads/develop 7297f41bd -> fa7b34054
Falcon: Updated guava.jar to the current release, 15.0 Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/fa7b3405 Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/fa7b3405 Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/fa7b3405 Branch: refs/heads/develop Commit: fa7b34054d72cf14d56956ec5b487c89c1ffd3b2 Parents: 7297f41 Author: Gordon Smith <[email protected]> Authored: Mon Nov 4 16:55:14 2013 -0800 Committer: Gordon Smith <[email protected]> Committed: Mon Nov 4 16:55:14 2013 -0800 ---------------------------------------------------------------------- .../problems/WorkspaceProblemFormatter.java | 45 +++++++++++--------- .../internal/projects/CompilerProject.java | 30 ++++++------- .../internal/scopes/ASProjectScope.java | 29 +++++++------ 3 files changed, 56 insertions(+), 48 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/fa7b3405/compiler/src/org/apache/flex/compiler/clients/problems/WorkspaceProblemFormatter.java ---------------------------------------------------------------------- diff --git a/compiler/src/org/apache/flex/compiler/clients/problems/WorkspaceProblemFormatter.java b/compiler/src/org/apache/flex/compiler/clients/problems/WorkspaceProblemFormatter.java index 0958ca9..a1a6df7 100644 --- a/compiler/src/org/apache/flex/compiler/clients/problems/WorkspaceProblemFormatter.java +++ b/compiler/src/org/apache/flex/compiler/clients/problems/WorkspaceProblemFormatter.java @@ -23,7 +23,6 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.LineNumberReader; import java.io.Reader; -import java.util.Map; import org.apache.commons.io.input.NullReader; @@ -32,8 +31,10 @@ import org.apache.flex.compiler.internal.workspaces.Workspace; import org.apache.flex.compiler.problems.CompilerProblemClassification; import org.apache.flex.compiler.problems.CompilerProblemSeverity; import org.apache.flex.compiler.problems.ICompilerProblem; -import com.google.common.base.Function; -import com.google.common.collect.MapMaker; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; /** * Problem formatter class that reports more detailed readable description of a @@ -60,7 +61,7 @@ public final class WorkspaceProblemFormatter extends ProblemFormatter private static String LOCATION_FORMAT_STRING = "%s:%d"; private final Workspace workspace; - private final Map<String, FileLineInfo> readers; + private final LoadingCache<String, FileLineInfo> readers; private final CompilerProblemCategorizer problemCategorizer; /** @@ -92,17 +93,18 @@ public final class WorkspaceProblemFormatter extends ProblemFormatter this.workspace = workspace; this.problemCategorizer = problemCategorizer; - readers = new MapMaker() - .concurrencyLevel(1) - .softValues() - .makeComputingMap(new Function<String, FileLineInfo>() { - - @Override - public FileLineInfo apply(String fileName) + readers = CacheBuilder.newBuilder() + .concurrencyLevel(1) + .softValues() + .build( + new CacheLoader<String, FileLineInfo>() { - return new FileLineInfo(fileName); - } - }); + @Override + public FileLineInfo load(String fileName) + { + return new FileLineInfo(fileName); + } + }); } @Override @@ -204,7 +206,7 @@ public final class WorkspaceProblemFormatter extends ProblemFormatter if (lineNumber < 0) return null; - FileLineInfo fileLineInfo = readers.get(filePath); + FileLineInfo fileLineInfo = readers.getUnchecked(filePath); return fileLineInfo.getLineText(lineNumber); } @@ -255,10 +257,11 @@ public final class WorkspaceProblemFormatter extends ProblemFormatter this.fileName = fileName; this.reader = createReader(); - cachedLines = new MapMaker().concurrencyLevel(1) - .softValues() - .maximumSize(MAX_CACHED_LINES_PER_FILE) - .makeMap(); + cachedLines = CacheBuilder.newBuilder() + .concurrencyLevel(1) + .softValues() + .maximumSize(MAX_CACHED_LINES_PER_FILE) + .build(); } private LineNumberReader createReader() @@ -279,11 +282,11 @@ public final class WorkspaceProblemFormatter extends ProblemFormatter final String fileName; LineNumberReader reader; - final Map<Integer, String> cachedLines; + final Cache<Integer, String> cachedLines; String getLineText(int lineNumber) { - String result = cachedLines.get(lineNumber); + String result = cachedLines.getIfPresent(lineNumber); if (result != null) return result; http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/fa7b3405/compiler/src/org/apache/flex/compiler/internal/projects/CompilerProject.java ---------------------------------------------------------------------- diff --git a/compiler/src/org/apache/flex/compiler/internal/projects/CompilerProject.java b/compiler/src/org/apache/flex/compiler/internal/projects/CompilerProject.java index a2e8a37..ae2cbd5 100644 --- a/compiler/src/org/apache/flex/compiler/internal/projects/CompilerProject.java +++ b/compiler/src/org/apache/flex/compiler/internal/projects/CompilerProject.java @@ -30,7 +30,6 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.WeakHashMap; -import java.util.concurrent.ConcurrentMap; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -64,8 +63,9 @@ import org.apache.flex.compiler.units.ICompilationUnit; import org.apache.flex.compiler.units.requests.IFileScopeRequestResult; import org.apache.flex.compiler.units.requests.IRequest; import org.apache.flex.utils.FilenameNormalization; -import com.google.common.base.Function; -import com.google.common.collect.MapMaker; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; /** * Abstract class used to share implementation of some ICompilerProject methods @@ -90,15 +90,15 @@ public abstract class CompilerProject implements ICompilerProject /** * Helper class to create new Scope Caches on the fly, when the scope cache map misses */ - static class ScopeMakerFunction implements Function<ASScope, ASScopeCache> + static class ScopeCacheLoader extends CacheLoader<ASScope, ASScopeCache> { CompilerProject project; - public ScopeMakerFunction(CompilerProject project) + public ScopeCacheLoader(CompilerProject project) { this.project = project; } @Override - public ASScopeCache apply(ASScope scope) + public ASScopeCache load(ASScope scope) { ASScopeCache cache = new ASScopeCache(project, scope); project.projectScope.addScopeToCompilationUnitScopeList(scope); @@ -111,11 +111,11 @@ public abstract class CompilerProject implements ICompilerProject * will go away once the corresponding scope has been gc'ed. Uses soft values so the caches may be collected * if the VM is running out of memory */ - private ConcurrentMap<ASScope, ASScopeCache> scopeCaches = new MapMaker() - .weakKeys() - .softValues() - .makeComputingMap( new ScopeMakerFunction(this) ); - + private LoadingCache<ASScope, ASScopeCache> scopeCaches = CacheBuilder.newBuilder() + .weakKeys() + .softValues() + .build(new ScopeCacheLoader(this)); + /** This thread local is to avoid every thread contending for access to the scopeCaches map, which is shared * across the entire Project. * When a scope cache is requested, we first check the thread local cache. If the entry is not present in @@ -235,7 +235,7 @@ public abstract class CompilerProject implements ICompilerProject scopeRequests.add(unit.getFileScopeRequest()); } - scopeCaches.clear(); + scopeCaches.invalidateAll(); initThreadLocalCaches(); projectScope.addAllExternallyVisibleDefinitions(scopeRequests); @@ -532,7 +532,7 @@ public abstract class CompilerProject implements ICompilerProject compilationUnit.clean(null, cusToUpdate, true); } - scopeCaches.clear(); + scopeCaches.invalidateAll(); initThreadLocalCaches(); } finally @@ -670,7 +670,7 @@ public abstract class CompilerProject implements ICompilerProject { // Didn't find it in the thread local, hit the shared cache, and cache those results // in the thread local so that we won't have to hit the shared cache next time. - scopeCache = scopeCaches.get(scope); + scopeCache = scopeCaches.getUnchecked(scope); cache.put(scope, new WeakReference<ASScopeCache>(scopeCache)); } @@ -717,7 +717,7 @@ public abstract class CompilerProject implements ICompilerProject assert scopes != null; for (IASScope scope : scopes) { - scopeCaches.remove(scope); + scopeCaches.invalidate(scope); } initThreadLocalCaches(); } http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/fa7b3405/compiler/src/org/apache/flex/compiler/internal/scopes/ASProjectScope.java ---------------------------------------------------------------------- diff --git a/compiler/src/org/apache/flex/compiler/internal/scopes/ASProjectScope.java b/compiler/src/org/apache/flex/compiler/internal/scopes/ASProjectScope.java index 5c61521..f2195be 100644 --- a/compiler/src/org/apache/flex/compiler/internal/scopes/ASProjectScope.java +++ b/compiler/src/org/apache/flex/compiler/internal/scopes/ASProjectScope.java @@ -36,6 +36,9 @@ import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import com.google.common.base.Function; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.MapMaker; @@ -172,7 +175,7 @@ public class ASProjectScope extends ASScopeBase IFileScope scope = (IFileScope)iasScope; if (scope != null) { - final Collection<IASScope> compilationUnitScopeList = compilationUnitToScopeList.get(cu); + final Collection<IASScope> compilationUnitScopeList = compilationUnitToScopeList.getUnchecked(cu); assert compilationUnitScopeList != null; compilationUnitScopeList.add(scope); ArrayList<IDefinition> externallVisibleDefs = new ArrayList<IDefinition>(); @@ -266,18 +269,18 @@ public class ASProjectScope extends ASScopeBase */ private Set<String> validImports; - // concurrent Map with weak keys - private final Map<ICompilationUnit, Collection<IASScope>> compilationUnitToScopeList = - new MapMaker().weakKeys().makeComputingMap( - new Function<ICompilationUnit, Collection<IASScope>>() + private final LoadingCache<ICompilationUnit, Collection<IASScope>> compilationUnitToScopeList = + CacheBuilder.newBuilder() + .weakKeys() + .build( + new CacheLoader<ICompilationUnit, Collection<IASScope>>() { @Override - public Collection<IASScope> apply(ICompilationUnit unit) + public Collection<IASScope> load(ICompilationUnit unit) { return new ConcurrentLinkedQueue<IASScope>(); } - } - ); + }); /** * Constructor. @@ -1302,7 +1305,7 @@ public class ASProjectScope extends ASScopeBase // of compilation unit to scopes, so we can easily invalidate the scope caches ICompilationUnit compilationUnit = getCompilationUnitForScope(scope); assert compilationUnit != null; - Collection<IASScope> relatedScopes = compilationUnitToScopeList.get(compilationUnit); + Collection<IASScope> relatedScopes = compilationUnitToScopeList.getUnchecked(compilationUnit); relatedScopes.add(scope); } @@ -1318,7 +1321,9 @@ public class ASProjectScope extends ASScopeBase */ public Collection<IASScope> clearCompilationUnitScopeList(ICompilationUnit compilationUnit) { - return compilationUnitToScopeList.remove(compilationUnit); + Collection<IASScope> scopeList = compilationUnitToScopeList.getUnchecked(compilationUnit); + compilationUnitToScopeList.invalidate(compilationUnit); + return scopeList; } /** @@ -1330,9 +1335,9 @@ public class ASProjectScope extends ASScopeBase */ public Collection<IASScope> getCompilationUnitScopeList(ICompilationUnit compilationUnit) { - if (!compilationUnitToScopeList.containsKey(compilationUnit)) + if (compilationUnitToScopeList.getIfPresent(compilationUnit) == null) return Collections.emptyList(); - Collection<IASScope> result = compilationUnitToScopeList.get(compilationUnit); + Collection<IASScope> result = compilationUnitToScopeList.getUnchecked(compilationUnit); assert result != null; assert !result.isEmpty(); return result;
