diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
5 files changed, 42 insertions, 24 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionLookupData.java b/src/main/java/com/google/devtools/build/lib/actions/ActionLookupData.java index 7c46b63bb0..9059267903 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ActionLookupData.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ActionLookupData.java @@ -14,28 +14,41 @@ package com.google.devtools.build.lib.actions; import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; +import com.google.common.collect.Interner; +import com.google.devtools.build.lib.actions.ActionLookupValue.ActionLookupKey; import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.concurrent.BlazeInterners; +import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec; +import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec; +import com.google.devtools.build.skyframe.SkyFunctionName; import com.google.devtools.build.skyframe.SkyKey; /** Data that uniquely identifies an action. */ -public class ActionLookupData { - private final SkyKey actionLookupNode; +@AutoCodec +public class ActionLookupData implements SkyKey { + private static final Interner<ActionLookupData> INTERNER = BlazeInterners.newWeakInterner(); + public static final SkyFunctionName NAME = SkyFunctionName.create("ACTION_EXECUTION"); + public static final ObjectCodec<ActionLookupData> CODEC = new ActionLookupData_AutoCodec(); + + private final ActionLookupKey actionLookupKey; private final int actionIndex; - public ActionLookupData(SkyKey actionLookupNode, int actionIndex) { - Preconditions.checkState( - actionLookupNode.argument() instanceof ActionLookupValue.ActionLookupKey, actionLookupNode); - this.actionLookupNode = actionLookupNode; + private ActionLookupData(ActionLookupKey actionLookupKey, int actionIndex) { + this.actionLookupKey = actionLookupKey; this.actionIndex = actionIndex; } - public SkyKey getActionLookupNode() { - return actionLookupNode; + @AutoCodec.Instantiator + public static ActionLookupData create(ActionLookupKey actionLookupKey, int actionIndex) { + return INTERNER.intern(new ActionLookupData(actionLookupKey, actionIndex)); + } + + public SkyKey getActionLookupKey() { + return actionLookupKey; } /** - * Index of the action in question in the node keyed by {@link #getActionLookupNode}. Should be + * Index of the action in question in the node keyed by {@link #getActionLookupKey}. Should be * passed to {@link ActionLookupValue#getAction}. */ public int getActionIndex() { @@ -43,12 +56,12 @@ public class ActionLookupData { } public Label getLabelForErrors() { - return ((ActionLookupValue.ActionLookupKey) actionLookupNode.argument()).getLabel(); + return ((ActionLookupKey) actionLookupKey.argument()).getLabel(); } @Override public int hashCode() { - return 37 * actionLookupNode.hashCode() + actionIndex; + return 37 * actionLookupKey.hashCode() + actionIndex; } @Override @@ -61,14 +74,19 @@ public class ActionLookupData { } ActionLookupData that = (ActionLookupData) obj; return this.actionIndex == that.actionIndex - && this.actionLookupNode.equals(that.actionLookupNode); + && this.actionLookupKey.equals(that.actionLookupKey); } @Override public String toString() { return MoreObjects.toStringHelper(this) - .add("actionLookupNode", actionLookupNode) + .add("actionLookupKey", actionLookupKey) .add("actionIndex", actionIndex) .toString(); } + + @Override + public SkyFunctionName functionName() { + return NAME; + } } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java index 4386023fa2..a450f6fc06 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java @@ -101,7 +101,7 @@ public class ActionExecutionFunction implements SkyFunction, CompletionReceiver InterruptedException { ActionLookupData actionLookupData = (ActionLookupData) skyKey.argument(); ActionLookupValue actionLookupValue = - (ActionLookupValue) env.getValue(actionLookupData.getActionLookupNode()); + (ActionLookupValue) env.getValue(actionLookupData.getActionLookupKey()); int actionIndex = actionLookupData.getActionIndex(); Action action = actionLookupValue.getAction(actionIndex); skyframeActionExecutor.noteActionEvaluationStarted(actionLookupData, action); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionValue.java index c377be7e27..105886a845 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionValue.java @@ -19,10 +19,10 @@ import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.actions.ActionLookupData; +import com.google.devtools.build.lib.actions.ActionLookupValue; import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe; -import com.google.devtools.build.skyframe.LegacySkyKey; import com.google.devtools.build.skyframe.SkyKey; import com.google.devtools.build.skyframe.SkyValue; import java.util.Map; @@ -132,9 +132,8 @@ public class ActionExecutionValue implements SkyValue { */ @ThreadSafe @VisibleForTesting - public static SkyKey key(SkyKey lookupKey, int index) { - return LegacySkyKey.create( - SkyFunctions.ACTION_EXECUTION, new ActionLookupData(lookupKey, index)); + public static SkyKey key(ActionLookupValue.ActionLookupKey lookupKey, int index) { + return ActionLookupData.create(lookupKey, index); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java index 5727adf638..6e6e4321ea 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java @@ -66,7 +66,7 @@ class ArtifactFunction implements SkyFunction { } } - SkyKey actionLookupKey = getActionLookupKey(artifact); + ActionLookupKey actionLookupKey = getActionLookupKey(artifact); ActionLookupValue actionLookupValue = getActionLookupValue(actionLookupKey, env, artifact); if (actionLookupValue == null) { return null; @@ -137,7 +137,8 @@ class ArtifactFunction implements SkyFunction { final ActionTemplate<?> actionTemplate, final Artifact treeArtifact, Environment env) throws InterruptedException { // Request the list of expanded actions from the ActionTemplate. - SkyKey templateKey = ActionTemplateExpansionValue.key(actionTemplate); + ActionTemplateExpansionValue.ActionTemplateExpansionKey templateKey = + ActionTemplateExpansionValue.key(actionTemplate); ActionTemplateExpansionValue expansionValue = (ActionTemplateExpansionValue) env.getValue(templateKey); @@ -309,7 +310,7 @@ class ArtifactFunction implements SkyFunction { } @VisibleForTesting - static SkyKey getActionLookupKey(Artifact artifact) { + static ActionLookupKey getActionLookupKey(Artifact artifact) { ArtifactOwner artifactOwner = artifact.getArtifactOwner(); Preconditions.checkState(artifactOwner instanceof ActionLookupKey, "", artifact, artifactOwner); diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyFunctions.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyFunctions.java index 04ff12caf5..a80d7616d8 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyFunctions.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyFunctions.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.skyframe; import com.google.common.base.Predicate; +import com.google.devtools.build.lib.actions.ActionLookupData; import com.google.devtools.build.skyframe.SkyFunctionName; import com.google.devtools.build.skyframe.SkyKey; @@ -86,8 +87,7 @@ public final class SkyFunctions { public static final SkyFunctionName CONFIGURATION_FRAGMENT = SkyFunctionName.create("CONFIGURATION_FRAGMENT"); public static final SkyFunctionName ARTIFACT = SkyFunctionName.create("ARTIFACT"); - public static final SkyFunctionName ACTION_EXECUTION = - SkyFunctionName.create("ACTION_EXECUTION"); + public static final SkyFunctionName ACTION_EXECUTION = ActionLookupData.NAME; public static final SkyFunctionName RECURSIVE_FILESYSTEM_TRAVERSAL = SkyFunctionName.create("RECURSIVE_DIRECTORY_TRAVERSAL"); public static final SkyFunctionName FILESET_ENTRY = SkyFunctionName.create("FILESET_ENTRY"); |