aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar Miguel Alcon Pinto <malcon@google.com>2015-10-08 21:31:27 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-10-09 14:41:31 +0000
commit37272108a4deb03720c65b4ad9b6fc29f43de327 (patch)
tree831d026e6ccc90bb88fc30b12258b0c5399f7b01 /src/main/java
parent2ba2108363c66e39eeff22c92dd7e3aa48956e09 (diff)
Replace LoadingCache<String, Label> with Interner<Label> in order to save memory.
-- MOS_MIGRATED_REVID=104998704
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java30
1 files changed, 7 insertions, 23 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java b/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java
index 6881c8712a..4a4ae10993 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/PackageDeserializer.java
@@ -17,13 +17,11 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
-import com.google.common.base.Throwables;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList.Builder;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Interner;
+import com.google.common.collect.Interners;
import com.google.common.collect.Sets;
import com.google.common.hash.HashCode;
import com.google.common.hash.Hasher;
@@ -56,7 +54,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -118,20 +115,7 @@ public class PackageDeserializer {
// Cache label deserialization across all instances- PackgeDeserializers need to be created on
// demand due to initialiation constraints wrt the setting of static members.
- private static final LoadingCache<String, Label> labelCache =
- CacheBuilder.newBuilder()
- .weakValues()
- .build(
- new CacheLoader<String, Label>() {
- @Override
- public Label load(String labelString) throws PackageDeserializationException {
- try {
- return Label.parseAbsolute(labelString);
- } catch (LabelSyntaxException e) {
- throw new PackageDeserializationException("Invalid label: " + e.getMessage(), e);
- }
- }
- });
+ private static final Interner<Label> LABEL_INTERNER = Interners.newWeakInterner();
/** Class encapsulating state for a single package deserialization. */
private static class DeserializationContext {
@@ -303,10 +287,10 @@ public class PackageDeserializer {
private static Label deserializeLabel(String labelName) throws PackageDeserializationException {
try {
- return labelCache.get(labelName);
- } catch (ExecutionException e) {
- Throwables.propagateIfInstanceOf(e.getCause(), PackageDeserializationException.class);
- throw new IllegalStateException("Failed to decode label: " + labelName, e);
+ return LABEL_INTERNER.intern(Label.parseAbsolute(labelName));
+ } catch (LabelSyntaxException e) {
+ throw new PackageDeserializationException(
+ "Invalid label '" + labelName + "':" + e.getMessage(), e);
}
}