diff options
author | 2017-11-03 17:09:44 +0100 | |
---|---|---|
committer | 2017-11-06 20:19:44 +0100 | |
commit | 405fdac18f215d573756156432c44c9ea4cd8632 (patch) | |
tree | b062c423af5041875e9be5184b3c6837e482083c /src/main/java | |
parent | 49a3e4bbcaaf801c3870f0918a17d460beafa0df (diff) |
Don't keep set of LTO backend artifacts on link action
Small cleanup to avoid saving a set of the LTOBackendArtifact objects on the
CppLinkAction. They can be accessed from the CppLinkActionBuilder, and
keeping them on the CppLinkAction prevents them from being GC'ed when
the builder is destroyed.
RELNOTES: None
PiperOrigin-RevId: 174469228
Diffstat (limited to 'src/main/java')
4 files changed, 8 insertions, 13 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java index ef193d0538..4e62783c3c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java @@ -332,7 +332,6 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { // Store immutable context for use in other *_binary rules that are implemented by // linking the interpreter (Java, Python, etc.) together with native deps. CppLinkAction.Context linkContext = new CppLinkAction.Context(linkActionBuilder); - Iterable<LtoBackendArtifacts> ltoBackendArtifacts = ImmutableList.of(); boolean usePic = CppHelper.usePic(ruleContext, !isLinkShared(ruleContext)); if (linkActionBuilder.hasLtoBitcodeInputs() @@ -342,8 +341,6 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { CppLinkAction indexAction = linkActionBuilder.build(); ruleContext.registerAction(indexAction); - ltoBackendArtifacts = indexAction.getAllLtoBackendArtifacts(); - linkActionBuilder.setLtoIndexing(false); } @@ -356,6 +353,8 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { } CppLinkAction linkAction = linkActionBuilder.build(); + Iterable<LtoBackendArtifacts> ltoBackendArtifacts = + linkActionBuilder.getAllLtoBackendArtifacts(); ruleContext.registerAction(linkAction); LibraryToLink outputLibrary = linkAction.getOutputLibrary(); Iterable<Artifact> fakeLinkerInputs = diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java index 609cd94d98..74522c5239 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkAction.java @@ -118,8 +118,6 @@ public final class CppLinkAction extends AbstractAction private final PathFragment ldExecutable; - // This is set for both LTO indexing and LTO linking. - @Nullable private final Iterable<LtoBackendArtifacts> allLtoBackendArtifacts; private final Iterable<Artifact> mandatoryInputs; // Linking uses a lot of memory; estimate 1 MB per input file, min 1.5 Gib. @@ -157,7 +155,6 @@ public final class CppLinkAction extends AbstractAction LibraryToLink interfaceOutputLibrary, boolean fake, boolean isLtoIndexing, - Iterable<LtoBackendArtifacts> allLtoBackendArtifacts, LinkCommandLine linkCommandLine, ImmutableSet<String> clientEnvironmentVariables, ImmutableMap<String, String> actionEnv, @@ -177,7 +174,6 @@ public final class CppLinkAction extends AbstractAction this.interfaceOutputLibrary = interfaceOutputLibrary; this.fake = fake; this.isLtoIndexing = isLtoIndexing; - this.allLtoBackendArtifacts = allLtoBackendArtifacts; this.linkCommandLine = linkCommandLine; this.clientEnvironmentVariables = clientEnvironmentVariables; this.actionEnv = actionEnv; @@ -297,10 +293,6 @@ public final class CppLinkAction extends AbstractAction return linkCommandLine.getLinkstamps(); } - Iterable<LtoBackendArtifacts> getAllLtoBackendArtifacts() { - return allLtoBackendArtifacts; - } - @Override @ThreadCompatible public ActionResult execute(ActionExecutionContext actionExecutionContext) diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java index 59b11dbff6..e5dd996fc2 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java @@ -930,7 +930,6 @@ public class CppLinkActionBuilder { interfaceOutputLibrary, fake, isLtoIndexing, - allLtoArtifacts, linkCommandLine, configuration.getVariableShellEnvironment(), configuration.getLocalShellEnvironment(), @@ -1027,6 +1026,11 @@ public class CppLinkActionBuilder { return this; } + /** Returns the set of LTO artifacts created during build() */ + public Iterable<LtoBackendArtifacts> getAllLtoBackendArtifacts() { + return allLtoArtifacts; + } + /** * This is the LTO indexing step, rather than the real link. * diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/DwoArtifactsCollector.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/DwoArtifactsCollector.java index 550ee409f3..362a6abf90 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/DwoArtifactsCollector.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/DwoArtifactsCollector.java @@ -61,7 +61,7 @@ public class DwoArtifactsCollector { picDwoBuilder.addAll(compilationOutputs.getPicDwoFiles()); // If we are generating .dwo, add any generated for LtoBackendArtifacts. - if (generateDwo) { + if (generateDwo && ltoBackendArtifacts != null) { for (LtoBackendArtifacts ltoBackendArtifact : ltoBackendArtifacts) { Artifact objectFile = ltoBackendArtifact.getObjectFile(); if (ltoBackendArtifactsUsePic) { |