diff options
author | 2017-05-01 17:37:46 +0200 | |
---|---|---|
committer | 2017-05-02 11:25:35 +0200 | |
commit | 38b835097f9ae9a6062172b8a33ec2e2d1edde20 (patch) | |
tree | ddd5ac16ff3470bdc39193dd6b69fcab6de0ab5a /src/main/java/com/google/devtools/build/lib/rules | |
parent | 2b49f678a7dfaf27afc0e44ed7a65b00ec06d413 (diff) |
Only allocate some formerly frequently allocated PathFragment objects once.
This reduces both gc churn and retained memory usage.
PiperOrigin-RevId: 154718782
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules')
8 files changed, 15 insertions, 10 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java index 74d1d3cdb0..1b1884ce8d 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java @@ -110,6 +110,8 @@ public class CppCompileAction extends AbstractAction } }; + private static final PathFragment BUILD_PATH_FRAGMENT = PathFragment.create("BUILD"); + private static final int VALIDATION_DEBUG = 0; // 0==none, 1==warns/errors, 2==all private static final boolean VALIDATION_DEBUG_WARN = VALIDATION_DEBUG >= 1; @@ -948,7 +950,7 @@ public class CppCompileAction extends AbstractAction // Still not found: see if it is in a subdir of a declared package. Path root = input.getRoot().getPath(); for (Path dir = input.getPath().getParentDirectory();;) { - if (dir.getRelative("BUILD").exists()) { + if (dir.getRelative(BUILD_PATH_FRAGMENT).exists()) { return false; // Bad: this is a sub-package, not a subdir of a declared package. } dir = dir.getParentDirectory(); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java index 693970c42e..333361f193 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java @@ -477,7 +477,7 @@ public class CppCompileActionBuilder { continue; } // One starting ../ is okay for getting to a sibling repository. - if (include.startsWith(PathFragment.create(Label.EXTERNAL_PATH_PREFIX))) { + if (include.startsWith(Label.EXTERNAL_PATH_PREFIX)) { include = include.relativeTo(Label.EXTERNAL_PATH_PREFIX); } if (include.isAbsolute() diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java index 41afb816ff..aa719c80ed 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java @@ -60,6 +60,8 @@ import javax.annotation.Nullable; * <p>This class can be used only after the loading phase. */ public class CppHelper { + static final PathFragment OBJS = PathFragment.create("_objs"); + private static final String GREPPED_INCLUDES_SUFFIX = ".includes"; // TODO(bazel-team): should this use Link.SHARED_LIBRARY_FILETYPES? @@ -283,7 +285,7 @@ public class CppHelper { * Returns the directory where object files are created. */ public static PathFragment getObjDirectory(Label ruleLabel) { - return AnalysisUtils.getUniqueDirectory(ruleLabel, PathFragment.create("_objs")); + return AnalysisUtils.getUniqueDirectory(ruleLabel, OBJS); } /** 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 b2a67113f8..0c640ff818 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 @@ -952,7 +952,7 @@ public class CppLinkActionBuilder { PathFragment stampOutputDirectory = outputBinaryPath .getParentDirectory() - .getRelative("_objs") + .getRelative(CppHelper.OBJS) .getRelative(outputBinaryPath.getBaseName()); for (Artifact linkstamp : linkstamps) { diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationHelper.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationHelper.java index 5389023701..e7b9c7c1cd 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationHelper.java @@ -71,6 +71,7 @@ public final class JavaCompilationHelper { private final ImmutableList<Artifact> additionalJavaBaseInputs; private static final String DEFAULT_ATTRIBUTES_SUFFIX = ""; + private static final PathFragment JAVAC = PathFragment.create("_javac"); public JavaCompilationHelper(RuleContext ruleContext, JavaSemantics semantics, ImmutableList<String> javacOpts, JavaTargetAttributes.Builder attributes, @@ -564,7 +565,7 @@ public final class JavaCompilationHelper { private PathFragment workDir(Artifact outputJar, String suffix) { String basename = FileSystemUtils.removeExtension(outputJar.getExecPath().getBaseName()); return getConfiguration().getBinDirectory(ruleContext.getRule().getRepository()).getExecPath() - .getRelative(ruleContext.getUniqueDirectory("_javac")) + .getRelative(ruleContext.getUniqueDirectory(JAVAC)) .getRelative(basename + suffix); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java index 337ee963c6..71cf24bc4e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IntermediateArtifacts.java @@ -33,6 +33,8 @@ import com.google.devtools.build.lib.vfs.PathFragment; // TODO(bazel-team): This should really be named DerivedArtifacts as it contains methods for // final as well as intermediate artifacts. public final class IntermediateArtifacts { + private static final PathFragment OBJS = PathFragment.create("_objs"); + static final String LINKMAP_SUFFIX = ".linkmap"; /** @@ -258,8 +260,7 @@ public final class IntermediateArtifacts { } private Artifact inUniqueObjsDir(Artifact source, String extension) { - PathFragment uniqueDir = - PathFragment.create("_objs").getRelative(ruleContext.getLabel().getName()); + PathFragment uniqueDir = OBJS.getRelative(ruleContext.getLabel().getName()); PathFragment sourceFile = uniqueDir.getRelative(source.getRootRelativePath()); PathFragment scopeRelativePath = FileSystemUtils.replaceExtension(sourceFile, extension); return scopedArtifact(scopeRelativePath); diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java index 490b1f6324..8d7e3eb5b2 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/repository/LocalRepositoryFunction.java @@ -100,7 +100,7 @@ public class LocalRepositoryFunction extends RepositoryFunction { directory.getRoot(), directory .getRelativePath() - .getChild(PackageLookupValue.BuildFileName.WORKSPACE.getFilename())); + .getRelative(PackageLookupValue.BuildFileName.WORKSPACE.getFilenameFragment())); SkyKey workspaceFileKey = FileValue.key(workspaceRootedFile); FileValue value; diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java index 20c26b5942..e6f3837212 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java @@ -473,8 +473,7 @@ public abstract class RepositoryFunction { if (repositoryPath.segmentCount() > 1) { if (rule.getRuleClass().equals(LocalRepositoryRule.NAME) - && repositoryPath.endsWith( - PathFragment.create(BuildFileName.WORKSPACE.getFilename()))) { + && repositoryPath.endsWith(BuildFileName.WORKSPACE.getFilenameFragment())) { // Ignore this, there is a dependency from LocalRepositoryFunction->WORKSPACE file already return; } |