Reduce interning memory overhead Part III -- Applies `SkyKeyInterner` to all `SkyKey`s that are using weak interner

https://github.com/bazelbuild/bazel/commit/836c608792fe20eeb29221861eb35932e9189db6 implements how `InMemoryGraph` interacts with `SkyKeyInterner`, and applies this feature only to `FileValue#Key`.

In this commit, we want to apply `SkyKeyInterner` to all `SkyKey`s using weak interner. Currently there are ~30 types of `SkyKey`s that use bazel weak interner.

PiperOrigin-RevId: 511521005
Change-Id: Ia6fb0fc2d494ac1b470268f7e263f7564d64a56b
diff --git a/src/main/java/com/google/devtools/build/lib/concurrent/BlazeInterners.java b/src/main/java/com/google/devtools/build/lib/concurrent/BlazeInterners.java
index 7c9d6dc..0546f48 100644
--- a/src/main/java/com/google/devtools/build/lib/concurrent/BlazeInterners.java
+++ b/src/main/java/com/google/devtools/build/lib/concurrent/BlazeInterners.java
@@ -35,6 +35,12 @@
     return builder.concurrencyLevel(CONCURRENCY_LEVEL);
   }
 
+  /**
+   * Creates an interner which retains a weak reference to each instance it has interned.
+   *
+   * <p>It is preferred to use {@code SkyKey#SkyKeyInterner} instead for interning {@code SkyKey}
+   * types.
+   */
   public static <T> Interner<T> newWeakInterner() {
     return setConcurrencyLevel(Interners.newBuilder().weak()).build();
   }
diff --git a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFileValue.java b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFileValue.java
index dac3b3b..efa5166 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFileValue.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFileValue.java
@@ -16,9 +16,7 @@
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Interner;
 import com.google.devtools.build.lib.cmdline.RepositoryName;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 import com.google.devtools.build.lib.vfs.RootedPath;
@@ -43,7 +41,7 @@
   @Immutable
   @AutoCodec
   public static class WorkspaceFileKey implements SkyKey {
-    private static final Interner<WorkspaceFileKey> interner = BlazeInterners.newWeakInterner();
+    private static final SkyKeyInterner<WorkspaceFileKey> interner = SkyKey.newInterner();
 
     private final RootedPath path;
     private final int idx;
@@ -93,6 +91,11 @@
     public String toString() {
       return path + ", " + idx;
     }
+
+    @Override
+    public SkyKeyInterner<WorkspaceFileKey> getSkyKeyInterner() {
+      return interner;
+    }
   }
 
   private final Package pkg;
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/AspectKeyCreator.java b/src/main/java/com/google/devtools/build/lib/skyframe/AspectKeyCreator.java
index fc34f04..fc4929b 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/AspectKeyCreator.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/AspectKeyCreator.java
@@ -16,16 +16,15 @@
 import com.google.common.base.Objects;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Interner;
 import com.google.devtools.build.lib.actions.ActionLookupKey;
 import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
 import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.packages.AspectClass;
 import com.google.devtools.build.lib.packages.AspectDescriptor;
 import com.google.devtools.build.lib.packages.AspectParameters;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 import com.google.devtools.build.skyframe.SkyFunctionName;
+import com.google.devtools.build.skyframe.SkyKey;
 import java.util.Comparator;
 import javax.annotation.Nullable;
 
@@ -85,7 +84,7 @@
   /** Represents an aspect applied to a particular target. */
   @AutoCodec
   public static final class AspectKey extends AspectBaseKey {
-    private static final Interner<AspectKey> interner = BlazeInterners.newWeakInterner();
+    private static final SkyKeyInterner<AspectKey> interner = SkyKey.newInterner();
 
     private final ImmutableList<AspectKey> baseKeys;
     private final AspectDescriptor aspectDescriptor;
@@ -234,6 +233,11 @@
           newBaseKeys.build(),
           aspectDescriptor);
     }
+
+    @Override
+    public SkyKeyInterner<AspectKey> getSkyKeyInterner() {
+      return interner;
+    }
   }
 
   /**
@@ -242,7 +246,7 @@
    */
   @AutoCodec
   public static final class TopLevelAspectsKey extends AspectBaseKey {
-    private static final Interner<TopLevelAspectsKey> interner = BlazeInterners.newWeakInterner();
+    private static final SkyKeyInterner<TopLevelAspectsKey> interner = SkyKey.newInterner();
 
     private final ImmutableList<AspectClass> topLevelAspectsClasses;
     private final Label targetLabel;
@@ -324,5 +328,10 @@
           && Objects.equal(topLevelAspectsClasses, that.topLevelAspectsClasses)
           && Objects.equal(topLevelAspectsParameters, that.topLevelAspectsParameters);
     }
+
+    @Override
+    public SkyKeyInterner<TopLevelAspectsKey> getSkyKeyInterner() {
+      return interner;
+    }
   }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BuildConfigurationKey.java b/src/main/java/com/google/devtools/build/lib/skyframe/BuildConfigurationKey.java
index c004ebb..19f338c 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/BuildConfigurationKey.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/BuildConfigurationKey.java
@@ -15,9 +15,7 @@
 package com.google.devtools.build.lib.skyframe;
 
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Interner;
 import com.google.devtools.build.lib.analysis.config.BuildOptions;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 import com.google.devtools.build.skyframe.SkyFunctionName;
 import com.google.devtools.build.skyframe.SkyKey;
@@ -57,7 +55,7 @@
     return interner.intern(new BuildConfigurationKey(options));
   }
 
-  private static final Interner<BuildConfigurationKey> interner = BlazeInterners.newWeakInterner();
+  private static final SkyKeyInterner<BuildConfigurationKey> interner = SkyKey.newInterner();
 
   private final BuildOptions options;
 
@@ -96,4 +94,9 @@
     // This format is depended on by integration tests.
     return "BuildConfigurationKey[" + options.checksum() + "]";
   }
+
+  @Override
+  public SkyKeyInterner<BuildConfigurationKey> getSkyKeyInterner() {
+    return interner;
+  }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BuildInfoCollectionValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/BuildInfoCollectionValue.java
index 4c82613..266b67c 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/BuildInfoCollectionValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/BuildInfoCollectionValue.java
@@ -14,7 +14,6 @@
 package com.google.devtools.build.lib.skyframe;
 
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Interner;
 import com.google.devtools.build.lib.actions.ActionLookupKey;
 import com.google.devtools.build.lib.actions.Actions.GeneratingActions;
 import com.google.devtools.build.lib.actions.BasicActionLookupValue;
@@ -22,9 +21,9 @@
 import com.google.devtools.build.lib.analysis.buildinfo.BuildInfoKey;
 import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
 import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 import com.google.devtools.build.skyframe.SkyFunctionName;
+import com.google.devtools.build.skyframe.SkyKey;
 import java.util.Objects;
 import javax.annotation.Nullable;
 
@@ -58,8 +57,7 @@
   /** Key for BuildInfoCollectionValues. */
   @AutoCodec
   public static final class BuildInfoKeyAndConfig extends ActionLookupKey {
-    private static final Interner<BuildInfoKeyAndConfig> keyInterner =
-        BlazeInterners.newWeakInterner();
+    private static final SkyKeyInterner<BuildInfoKeyAndConfig> keyInterner = SkyKey.newInterner();
 
     private final BuildInfoKey infoKey;
     private final BuildConfigurationKey configKey;
@@ -114,5 +112,10 @@
       return Objects.equals(this.infoKey, that.infoKey)
           && Objects.equals(this.configKey, that.configKey);
     }
+
+    @Override
+    public SkyKeyInterner<BuildInfoKeyAndConfig> getSkyKeyInterner() {
+      return keyInterner;
+    }
   }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BuildTopLevelAspectsDetailsFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/BuildTopLevelAspectsDetailsFunction.java
index aac6b4d..d2f5dd5 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/BuildTopLevelAspectsDetailsFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/BuildTopLevelAspectsDetailsFunction.java
@@ -19,10 +19,8 @@
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Interner;
 import com.google.devtools.build.lib.analysis.AspectCollection;
 import com.google.devtools.build.lib.analysis.AspectCollection.AspectCycleOnPathException;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.events.Event;
 import com.google.devtools.build.lib.packages.Aspect;
 import com.google.devtools.build.lib.packages.AspectClass;
@@ -244,8 +242,8 @@
   /** {@link SkyKey} for building top-level aspects details. */
   @AutoCodec
   static final class BuildTopLevelAspectsDetailsKey implements SkyKey {
-    private static final Interner<BuildTopLevelAspectsDetailsKey> interner =
-        BlazeInterners.newWeakInterner();
+    private static final SkyKeyInterner<BuildTopLevelAspectsDetailsKey> interner =
+        SkyKey.newInterner();
 
     private final ImmutableList<AspectClass> topLevelAspectsClasses;
     private final ImmutableMap<String, String> topLevelAspectsParameters;
@@ -311,6 +309,11 @@
           .add("topLevelAspectsParameters", topLevelAspectsParameters)
           .toString();
     }
+
+    @Override
+    public SkyKeyInterner<BuildTopLevelAspectsDetailsKey> getSkyKeyInterner() {
+      return interner;
+    }
   }
 
   /**
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BzlCompileValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/BzlCompileValue.java
index c599e7e..02e52f3 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/BzlCompileValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/BzlCompileValue.java
@@ -15,9 +15,7 @@
 package com.google.devtools.build.lib.skyframe;
 
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Interner;
 import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant;
 import com.google.devtools.build.lib.vfs.Root;
@@ -132,8 +130,6 @@
     return new Success(prog, digest);
   }
 
-  private static final Interner<Key> keyInterner = BlazeInterners.newWeakInterner();
-
   /** Types of bzl files we may encounter. */
   enum Kind {
     /** A regular .bzl file loaded on behalf of a BUILD or WORKSPACE file. */
@@ -159,6 +155,8 @@
   /** SkyKey for retrieving a compiled .bzl program. */
   @AutoCodec
   public static class Key implements SkyKey {
+    private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();
+
     /** The root in which the .bzl file is to be found. Null for EMPTY_PRELUDE. */
     @Nullable final Root root;
 
@@ -180,7 +178,7 @@
     @AutoCodec.VisibleForSerialization
     @AutoCodec.Instantiator
     static Key create(Root root, Label label, Kind kind) {
-      return keyInterner.intern(new Key(root, label, kind));
+      return interner.intern(new Key(root, label, kind));
     }
 
     /** Returns whether this key is for a {@code @_builtins} .bzl file. */
@@ -225,6 +223,11 @@
     public String toString() {
       return String.format("%s:[%s]%s", functionName(), root, label);
     }
+
+    @Override
+    public SkyKeyInterner<Key> getSkyKeyInterner() {
+      return interner;
+    }
   }
 
   /** Constructs a key for loading a regular (non-prelude) .bzl. */
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BzlLoadValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/BzlLoadValue.java
index 225898a..d78c26a 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/BzlLoadValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/BzlLoadValue.java
@@ -17,9 +17,7 @@
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.MoreObjects;
-import com.google.common.collect.Interner;
 import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
 import com.google.devtools.build.lib.packages.BzlVisibility;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
@@ -27,6 +25,7 @@
 import com.google.devtools.build.lib.vfs.RootedPath;
 import com.google.devtools.build.skyframe.SkyFunctionName;
 import com.google.devtools.build.skyframe.SkyKey;
+import com.google.devtools.build.skyframe.SkyKey.SkyKeyInterner;
 import com.google.devtools.build.skyframe.SkyValue;
 import java.util.Objects;
 import net.starlark.java.eval.Module;
@@ -70,7 +69,7 @@
     return bzlVisibility;
   }
 
-  private static final Interner<Key> keyInterner = BlazeInterners.newWeakInterner();
+  private static final SkyKeyInterner<Key> keyInterner = SkyKey.newInterner();
 
   /** SkyKey for a Starlark load. */
   public abstract static class Key implements SkyKey {
@@ -157,6 +156,11 @@
     public String toString() {
       return toStringHelper().toString();
     }
+
+    @Override
+    public SkyKeyInterner<Key> getSkyKeyInterner() {
+      return keyInterner;
+    }
   }
 
   /** A key for loading a .bzl during package loading (BUILD evaluation). */
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ClientEnvironmentFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ClientEnvironmentFunction.java
index 60bc5ad..d95edd9 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ClientEnvironmentFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ClientEnvironmentFunction.java
@@ -14,8 +14,6 @@
 
 package com.google.devtools.build.lib.skyframe;
 
-import com.google.common.collect.Interner;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 import com.google.devtools.build.skyframe.AbstractSkyKey;
 import com.google.devtools.build.skyframe.SkyFunction;
@@ -35,7 +33,7 @@
   @AutoCodec.VisibleForSerialization
   @AutoCodec
   static class Key extends AbstractSkyKey<String> {
-    private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
+    private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();
 
     private Key(String arg) {
       super(arg);
@@ -51,6 +49,11 @@
     public SkyFunctionName functionName() {
       return SkyFunctions.CLIENT_ENVIRONMENT_VARIABLE;
     }
+
+    @Override
+    public SkyKeyInterner<Key> getSkyKeyInterner() {
+      return interner;
+    }
   }
 
   private final AtomicReference<Map<String, String>> clientEnv;
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetKey.java b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetKey.java
index a4c504c..ea4c2c5 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetKey.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ConfiguredTargetKey.java
@@ -17,14 +17,13 @@
 import static com.google.common.base.Preconditions.checkNotNull;
 
 import com.google.common.base.MoreObjects;
-import com.google.common.collect.Interner;
 import com.google.devtools.build.lib.actions.ActionLookupKey;
 import com.google.devtools.build.lib.analysis.ConfiguredTarget;
 import com.google.devtools.build.lib.analysis.config.BuildConfigurationValue;
 import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 import com.google.devtools.build.skyframe.SkyFunctionName;
+import com.google.devtools.build.skyframe.SkyKey;
 import com.google.errorprone.annotations.CanIgnoreReturnValue;
 import java.util.Objects;
 import javax.annotation.Nullable;
@@ -63,7 +62,7 @@
    * Cache so that the number of ConfiguredTargetKey instances is {@code O(configured targets)} and
    * not {@code O(edges between configured targets)}.
    */
-  private static final Interner<ConfiguredTargetKey> interner = BlazeInterners.newWeakInterner();
+  private static final SkyKeyInterner<ConfiguredTargetKey> interner = SkyKey.newInterner();
 
   private final Label label;
   @Nullable private final BuildConfigurationKey configurationKey;
@@ -161,11 +160,16 @@
     return helper.toString();
   }
 
+  @Override
+  public SkyKeyInterner<? extends ConfiguredTargetKey> getSkyKeyInterner() {
+    return interner;
+  }
+
   @AutoCodec.VisibleForSerialization
   @AutoCodec
   static class ToolchainDependencyConfiguredTargetKey extends ConfiguredTargetKey {
-    private static final Interner<ToolchainDependencyConfiguredTargetKey>
-        toolchainDependencyConfiguredTargetKeyInterner = BlazeInterners.newWeakInterner();
+    private static final SkyKeyInterner<ToolchainDependencyConfiguredTargetKey>
+        toolchainDependencyConfiguredTargetKeyInterner = SkyKey.newInterner();
 
     private final Label executionPlatformLabel;
 
@@ -194,6 +198,11 @@
     public final Label getExecutionPlatformLabel() {
       return executionPlatformLabel;
     }
+
+    @Override
+    public final SkyKeyInterner<? extends ConfiguredTargetKey> getSkyKeyInterner() {
+      return toolchainDependencyConfiguredTargetKeyInterner;
+    }
   }
 
   /** Returns a new {@link Builder} to create instances of {@link ConfiguredTargetKey}. */
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupValue.java
index 39449b2..444c15b 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupValue.java
@@ -16,16 +16,15 @@
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Interner;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.cmdline.PackageIdentifier;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant;
 import com.google.devtools.build.lib.vfs.PathFragment;
 import com.google.devtools.build.lib.vfs.Root;
 import com.google.devtools.build.skyframe.AbstractSkyKey;
 import com.google.devtools.build.skyframe.SkyFunctionName;
+import com.google.devtools.build.skyframe.SkyKey;
 import com.google.devtools.build.skyframe.SkyValue;
 import javax.annotation.Nonnull;
 
@@ -108,7 +107,7 @@
   /** {@link com.google.devtools.build.skyframe.SkyKey} for {@code ContainingPackageLookupValue}. */
   @AutoCodec
   public static class Key extends AbstractSkyKey<PackageIdentifier> {
-    private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
+    private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();
 
     private Key(PackageIdentifier arg) {
       super(arg);
@@ -124,6 +123,11 @@
     public SkyFunctionName functionName() {
       return SkyFunctions.CONTAINING_PACKAGE_LOOKUP;
     }
+
+    @Override
+    public SkyKeyInterner<Key> getSkyKeyInterner() {
+      return interner;
+    }
   }
 
   public static ContainingPackage withContainingPackage(PackageIdentifier pkgId, Root root) {
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/DirectoryListingStateValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/DirectoryListingStateValue.java
index c807df9..14975e3 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/DirectoryListingStateValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/DirectoryListingStateValue.java
@@ -15,15 +15,14 @@
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Interner;
 import com.google.common.collect.Iterables;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 import com.google.devtools.build.lib.vfs.Dirent;
 import com.google.devtools.build.lib.vfs.RootedPath;
 import com.google.devtools.build.skyframe.AbstractSkyKey;
 import com.google.devtools.build.skyframe.SkyFunctionName;
+import com.google.devtools.build.skyframe.SkyKey;
 import com.google.devtools.build.skyframe.SkyValue;
 import java.util.Arrays;
 import java.util.BitSet;
@@ -61,7 +60,7 @@
   @AutoCodec.VisibleForSerialization
   @AutoCodec
   public static class Key extends AbstractSkyKey<RootedPath> {
-    private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
+    private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();
 
     private Key(RootedPath arg) {
       super(arg);
@@ -77,6 +76,11 @@
     public SkyFunctionName functionName() {
       return SkyFunctions.DIRECTORY_LISTING_STATE;
     }
+
+    @Override
+    public SkyKeyInterner<Key> getSkyKeyInterner() {
+      return interner;
+    }
   }
 
   /**
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/DirectoryListingValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/DirectoryListingValue.java
index 8e8b2df..8ec47233 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/DirectoryListingValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/DirectoryListingValue.java
@@ -13,15 +13,14 @@
 // limitations under the License.
 package com.google.devtools.build.lib.skyframe;
 
-import com.google.common.collect.Interner;
 import com.google.devtools.build.lib.actions.FileValue;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 import com.google.devtools.build.lib.vfs.RootedPath;
 import com.google.devtools.build.skyframe.AbstractSkyKey;
 import com.google.devtools.build.skyframe.SkyFunctionName;
+import com.google.devtools.build.skyframe.SkyKey;
 import com.google.devtools.build.skyframe.SkyValue;
 import java.util.Objects;
 
@@ -66,7 +65,7 @@
   @AutoCodec.VisibleForSerialization
   @AutoCodec
   public static class Key extends AbstractSkyKey<RootedPath> {
-    private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
+    private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();
 
     private Key(RootedPath arg) {
       super(arg);
@@ -82,6 +81,11 @@
     public SkyFunctionName functionName() {
       return SkyFunctions.DIRECTORY_LISTING;
     }
+
+    @Override
+    public SkyKeyInterner<Key> getSkyKeyInterner() {
+      return interner;
+    }
   }
 
   static DirectoryListingValue value(RootedPath dirRootedPath, FileValue dirFileValue,
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/GlobDescriptor.java b/src/main/java/com/google/devtools/build/lib/skyframe/GlobDescriptor.java
index a436090..f752689 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/GlobDescriptor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/GlobDescriptor.java
@@ -14,9 +14,7 @@
 package com.google.devtools.build.lib.skyframe;
 
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Interner;
 import com.google.devtools.build.lib.cmdline.PackageIdentifier;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
 import com.google.devtools.build.lib.packages.Globber;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
@@ -37,7 +35,7 @@
 @ThreadSafe
 public final class GlobDescriptor implements SkyKey {
 
-  private static final Interner<GlobDescriptor> interner = BlazeInterners.newWeakInterner();
+  private static final SkyKeyInterner<GlobDescriptor> interner = SkyKey.newInterner();
 
   /**
    * Returns interned instance based on the parameters.
@@ -155,4 +153,9 @@
   public SkyFunctionName functionName() {
     return SkyFunctions.GLOB;
   }
+
+  @Override
+  public SkyKeyInterner<GlobDescriptor> getSkyKeyInterner() {
+    return interner;
+  }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/IgnoredPackagePrefixesValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/IgnoredPackagePrefixesValue.java
index 82af376..71c5716 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/IgnoredPackagePrefixesValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/IgnoredPackagePrefixesValue.java
@@ -15,9 +15,7 @@
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Interner;
 import com.google.devtools.build.lib.cmdline.RepositoryName;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.SerializationConstant;
 import com.google.devtools.build.lib.vfs.PathFragment;
@@ -73,7 +71,7 @@
   @AutoCodec.VisibleForSerialization
   @AutoCodec
   static class Key extends AbstractSkyKey<RepositoryName> {
-    private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
+    private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();
 
     private Key(RepositoryName arg) {
       super(arg);
@@ -89,5 +87,10 @@
     public SkyFunctionName functionName() {
       return SkyFunctions.IGNORED_PACKAGE_PREFIXES;
     }
+
+    @Override
+    public SkyKeyInterner<Key> getSkyKeyInterner() {
+      return interner;
+    }
   }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupValue.java
index 562ce5e..d3a4977 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupValue.java
@@ -15,9 +15,7 @@
 
 import com.google.common.base.Objects;
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Interner;
 import com.google.devtools.build.lib.cmdline.PackageIdentifier;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.packages.BuildFileName;
 import com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
@@ -138,7 +136,7 @@
   @AutoCodec.VisibleForSerialization
   @AutoCodec
   static class Key extends AbstractSkyKey<PackageIdentifier> {
-    private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
+    private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();
 
     private Key(PackageIdentifier arg) {
       super(arg);
@@ -154,6 +152,11 @@
     public SkyFunctionName functionName() {
       return SkyFunctions.PACKAGE_LOOKUP;
     }
+
+    @Override
+    public SkyKeyInterner<Key> getSkyKeyInterner() {
+      return interner;
+    }
   }
 
   /** Successful lookup value. */
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageValue.java
index 1918e83..26cc390 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageValue.java
@@ -15,9 +15,7 @@
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Interner;
 import com.google.devtools.build.lib.cmdline.PackageIdentifier;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
 import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
 import com.google.devtools.build.lib.packages.Package;
@@ -64,7 +62,7 @@
   @AutoCodec.VisibleForSerialization
   @AutoCodec
   public static class Key extends AbstractSkyKey<PackageIdentifier> implements CPUHeavySkyKey {
-    private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
+    private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();
 
     private Key(PackageIdentifier arg) {
       super(arg);
@@ -80,6 +78,11 @@
     public SkyFunctionName functionName() {
       return SkyFunctions.PACKAGE;
     }
+
+    @Override
+    public SkyKeyInterner<Key> getSkyKeyInterner() {
+      return interner;
+    }
   }
 
   public static ImmutableList<SkyKey> keys(Iterable<PackageIdentifier> pkgIdentifiers) {
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PlatformMappingValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/PlatformMappingValue.java
index 61a1ca8..389f48e 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PlatformMappingValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PlatformMappingValue.java
@@ -24,13 +24,11 @@
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Interner;
 import com.google.common.collect.Iterables;
 import com.google.devtools.build.lib.analysis.PlatformOptions;
 import com.google.devtools.build.lib.analysis.config.BuildOptions;
 import com.google.devtools.build.lib.analysis.config.FragmentOptions;
 import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.concurrent.ThreadSafety;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 import com.google.devtools.build.lib.vfs.PathFragment;
@@ -61,7 +59,7 @@
   @ThreadSafety.Immutable
   @AutoCodec
   public static final class Key implements SkyKey {
-    private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
+    private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();
 
     /**
      * Creates a new platform mappings key with the given, main workspace-relative path to the
@@ -134,6 +132,11 @@
           + wasExplicitlySetByUser
           + "}";
     }
+
+    @Override
+    public SkyKeyInterner<Key> getSkyKeyInterner() {
+      return interner;
+    }
   }
 
   private final ImmutableMap<Label, ImmutableSet<String>> platformsToFlags;
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java
index f77646d..1b56eca 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PrecomputedValue.java
@@ -18,9 +18,7 @@
 import com.google.common.base.Preconditions;
 import com.google.common.base.Supplier;
 import com.google.common.base.Suppliers;
-import com.google.common.collect.Interner;
 import com.google.devtools.build.lib.analysis.config.BuildOptions;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.packages.Package.ConfigSettingVisibilityPolicy;
 import com.google.devtools.build.lib.packages.RuleVisibility;
 import com.google.devtools.build.lib.pkgcache.PathPackageLocator;
@@ -187,7 +185,7 @@
   /** {@link com.google.devtools.build.skyframe.SkyKey} for {@code PrecomputedValue}. */
   @AutoCodec
   public static final class Key extends AbstractSkyKey<String> {
-    private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
+    private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();
 
     private Key(String arg) {
       super(arg);
@@ -202,13 +200,18 @@
     public SkyFunctionName functionName() {
       return SkyFunctions.PRECOMPUTED;
     }
+
+    @Override
+    public SkyKeyInterner<Key> getSkyKeyInterner() {
+      return interner;
+    }
   }
 
   /** Unshareable version of {@link Key}. */
   @AutoCodec
   @VisibleForSerialization
   static final class UnshareableKey extends AbstractSkyKey<String> {
-    private static final Interner<UnshareableKey> interner = BlazeInterners.newWeakInterner();
+    private static final SkyKeyInterner<UnshareableKey> interner = SkyKey.newInterner();
 
     private UnshareableKey(String arg) {
       super(arg);
@@ -229,5 +232,10 @@
     public boolean valueIsShareable() {
       return false;
     }
+
+    @Override
+    public SkyKeyInterner<UnshareableKey> getSkyKeyInterner() {
+      return interner;
+    }
   }
 }
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsValue.java
index df534c0..f8ee577 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredExecutionPlatformsValue.java
@@ -16,8 +16,6 @@
 
 import com.google.auto.value.AutoValue;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Interner;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 import com.google.devtools.build.skyframe.SkyFunctionName;
 import com.google.devtools.build.skyframe.SkyKey;
@@ -39,7 +37,7 @@
   @AutoCodec
   @AutoCodec.VisibleForSerialization
   static class Key implements SkyKey {
-    private static final Interner<Key> interners = BlazeInterners.newWeakInterner();
+    private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();
 
     private final BuildConfigurationKey configurationKey;
 
@@ -50,7 +48,7 @@
     @AutoCodec.Instantiator
     @AutoCodec.VisibleForSerialization
     static Key of(BuildConfigurationKey configurationKey) {
-      return interners.intern(new Key(configurationKey));
+      return interner.intern(new Key(configurationKey));
     }
 
     @Override
@@ -75,6 +73,11 @@
     public int hashCode() {
       return configurationKey.hashCode();
     }
+
+    @Override
+    public final SkyKeyInterner<Key> getSkyKeyInterner() {
+      return interner;
+    }
   }
 
   static RegisteredExecutionPlatformsValue create(
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsValue.java
index bb14011..01fa349 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsValue.java
@@ -16,9 +16,7 @@
 
 import com.google.auto.value.AutoValue;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Interner;
 import com.google.devtools.build.lib.analysis.platform.DeclaredToolchainInfo;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 import com.google.devtools.build.skyframe.SkyFunctionName;
 import com.google.devtools.build.skyframe.SkyKey;
@@ -39,7 +37,7 @@
   /** A {@link SkyKey} for {@code RegisteredToolchainsValue}. */
   @AutoCodec
   static class Key implements SkyKey {
-    private static final Interner<Key> interners = BlazeInterners.newWeakInterner();
+    private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();
 
     private final BuildConfigurationKey configurationKey;
 
@@ -50,7 +48,7 @@
     @AutoCodec.Instantiator
     @AutoCodec.VisibleForSerialization
     static Key of(BuildConfigurationKey configurationKey) {
-      return interners.intern(new Key(configurationKey));
+      return interner.intern(new Key(configurationKey));
     }
 
     @Override
@@ -85,6 +83,11 @@
     public int hashCode() {
       return configurationKey.hashCode();
     }
+
+    @Override
+    public final SkyKeyInterner<Key> getSkyKeyInterner() {
+      return interner;
+    }
   }
 
   public static RegisteredToolchainsValue create(
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RepositoryMappingValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/RepositoryMappingValue.java
index 1ed0f2f..6af4ac1 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RepositoryMappingValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RepositoryMappingValue.java
@@ -16,10 +16,8 @@
 
 import com.google.auto.value.AutoValue;
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Interner;
 import com.google.devtools.build.lib.cmdline.RepositoryMapping;
 import com.google.devtools.build.lib.cmdline.RepositoryName;
-import com.google.devtools.build.lib.concurrent.BlazeInterners;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 import com.google.devtools.build.lib.util.DetailedExitCode;
 import com.google.devtools.build.lib.util.ExitCode;
@@ -103,7 +101,7 @@
   @AutoValue
   public abstract static class Key implements SkyKey {
 
-    private static final Interner<Key> interner = BlazeInterners.newWeakInterner();
+    private static final SkyKeyInterner<Key> interner = SkyKey.newInterner();
 
     /** The name of the repo to grab mappings for. */
     public abstract RepositoryName repoName();
@@ -124,6 +122,11 @@
     public SkyFunctionName functionName() {
       return SkyFunctions.REPOSITORY_MAPPING;
     }
+
+    @Override
+    public SkyKeyInterner<Key> getSkyKeyInterner() {
+      return interner;
+    }
   }
 
   /**