Skip to content

Commit b59fbee

Browse files
fmeumcopybara-github
authored andcommitted
Remove allocation instrumenter jar and update version in docs
The jar can be supplied separately as it needs to be passed to the `-javaagent` JVM arg anyway. Also update the recommended version for compatibility with Java 21. Fixes bazelbuild#24782 Closes bazelbuild#24783. PiperOrigin-RevId: 714057306 Change-Id: Ic8d47562f15344ed16d0af5d3242937d2ee53b22
1 parent edb2b06 commit b59fbee

File tree

10 files changed

+74
-53
lines changed

10 files changed

+74
-53
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ maven.install(
107107
"com.google.auto.value:auto-value-annotations:1.11.0",
108108
"com.google.code.findbugs:jsr305:3.0.2",
109109
"com.google.code.gson:gson:2.10.1",
110-
"com.google.code.java-allocation-instrumenter:java-allocation-instrumenter:3.3.0",
110+
"com.google.code.java-allocation-instrumenter:java-allocation-instrumenter:3.3.4",
111111
"com.google.errorprone:error_prone_annotation:2.36.0",
112112
"com.google.errorprone:error_prone_annotations:2.36.0",
113113
"com.google.errorprone:error_prone_check_api:2.36.0",

maven_install.json

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
3-
"__INPUT_ARTIFACTS_HASH": -44489190,
4-
"__RESOLVED_ARTIFACTS_HASH": 1526283480,
3+
"__INPUT_ARTIFACTS_HASH": -1897763682,
4+
"__RESOLVED_ARTIFACTS_HASH": -165154966,
55
"conflict_resolution": {
66
"com.google.api.grpc:proto-google-common-protos:2.29.0": "com.google.api.grpc:proto-google-common-protos:2.41.0",
77
"com.google.auth:google-auth-library-credentials:1.6.0": "com.google.auth:google-auth-library-credentials:1.23.0",
@@ -189,9 +189,9 @@
189189
},
190190
"com.google.code.java-allocation-instrumenter:java-allocation-instrumenter": {
191191
"shasums": {
192-
"jar": "1ef5535a8bd41cf3072469f381b9ee6ab28275311a7499f53d6e52adf976fef0"
192+
"jar": "44f8cddec129520b2532fa9ff25f9572d7566307d660635ba32bf409f06ae336"
193193
},
194-
"version": "3.3.0"
194+
"version": "3.3.4"
195195
},
196196
"com.google.dagger:dagger": {
197197
"shasums": {
@@ -1128,15 +1128,6 @@
11281128
"com.google.code.gson:gson": [
11291129
"com.google.errorprone:error_prone_annotations"
11301130
],
1131-
"com.google.code.java-allocation-instrumenter:java-allocation-instrumenter": [
1132-
"com.google.guava:guava",
1133-
"javax.annotation:javax.annotation-api",
1134-
"org.ow2.asm:asm",
1135-
"org.ow2.asm:asm-analysis",
1136-
"org.ow2.asm:asm-commons",
1137-
"org.ow2.asm:asm-tree",
1138-
"org.ow2.asm:asm-util"
1139-
],
11401131
"com.google.dagger:dagger": [
11411132
"javax.inject:javax.inject"
11421133
],
@@ -1981,30 +1972,16 @@
19811972
"com.google.monitoring.runtime.instrumentation.asm.commons",
19821973
"com.google.monitoring.runtime.instrumentation.asm.signature",
19831974
"com.google.monitoring.runtime.instrumentation.asm.tree",
1984-
"com.google.monitoring.runtime.instrumentation.asm.tree.analysis",
1985-
"com.google.monitoring.runtime.instrumentation.asm.util",
1986-
"com.google.monitoring.runtime.instrumentation.checker.nullness.compatqual",
1987-
"com.google.monitoring.runtime.instrumentation.common.annotations",
1988-
"com.google.monitoring.runtime.instrumentation.common.base",
1989-
"com.google.monitoring.runtime.instrumentation.common.base.internal",
1990-
"com.google.monitoring.runtime.instrumentation.common.cache",
1991-
"com.google.monitoring.runtime.instrumentation.common.collect",
1992-
"com.google.monitoring.runtime.instrumentation.common.escape",
1993-
"com.google.monitoring.runtime.instrumentation.common.eventbus",
1994-
"com.google.monitoring.runtime.instrumentation.common.graph",
1995-
"com.google.monitoring.runtime.instrumentation.common.hash",
1996-
"com.google.monitoring.runtime.instrumentation.common.html",
1997-
"com.google.monitoring.runtime.instrumentation.common.io",
1998-
"com.google.monitoring.runtime.instrumentation.common.math",
1999-
"com.google.monitoring.runtime.instrumentation.common.net",
2000-
"com.google.monitoring.runtime.instrumentation.common.primitives",
2001-
"com.google.monitoring.runtime.instrumentation.common.reflect",
2002-
"com.google.monitoring.runtime.instrumentation.common.util.concurrent",
2003-
"com.google.monitoring.runtime.instrumentation.common.xml",
2004-
"com.google.monitoring.runtime.instrumentation.errorprone.annotations",
2005-
"com.google.monitoring.runtime.instrumentation.errorprone.annotations.concurrent",
2006-
"com.google.monitoring.runtime.instrumentation.j2objc.annotations",
2007-
"com.google.thirdparty.publicsuffix"
1975+
"com.google.monitoring.runtime.instrumentation.common.com.google.common.annotations",
1976+
"com.google.monitoring.runtime.instrumentation.common.com.google.common.base",
1977+
"com.google.monitoring.runtime.instrumentation.common.com.google.common.cache",
1978+
"com.google.monitoring.runtime.instrumentation.common.com.google.common.collect",
1979+
"com.google.monitoring.runtime.instrumentation.common.com.google.common.math",
1980+
"com.google.monitoring.runtime.instrumentation.common.com.google.common.primitives",
1981+
"com.google.monitoring.runtime.instrumentation.common.com.google.common.util.concurrent",
1982+
"com.google.monitoring.runtime.instrumentation.common.com.google.common.util.concurrent.internal",
1983+
"javax.annotation",
1984+
"javax.annotation.security"
20081985
],
20091986
"com.google.dagger:dagger": [
20101987
"dagger",

site/en/docs/user-manual.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,30 +2178,30 @@ Following options are supported:
21782178
Some `dump` commands require memory tracking. To turn this on, you have to pass
21792179
startup flags to Bazel:
21802180

2181-
* `--host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.3.0.jar`
2181+
* `--host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.3.4.jar`
21822182
* `--host_jvm_args=-DRULE_MEMORY_TRACKER=1`
21832183

21842184
The java-agent is checked into Bazel at
2185-
`third_party/allocation_instrumenter/java-allocation-instrumenter-3.3.0.jar`, so make
2186-
sure you adjust `$BAZEL` for where you keep your Bazel repository.
2185+
`third_party/allocation_instrumenter/java-allocation-instrumenter-3.3.4.jar`, so
2186+
make sure you adjust `$BAZEL` for where you keep your Bazel repository.
21872187

21882188
Do not forget to keep passing these options to Bazel for every command or the server will
21892189
restart.
21902190

21912191
Example:
21922192

21932193
<pre>
2194-
% bazel --host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.3.0.jar \
2194+
% bazel --host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.3.4.jar \
21952195
--host_jvm_args=-DRULE_MEMORY_TRACKER=1 \
21962196
build --nobuild &lt;targets&gt;
21972197

21982198
# Dump rules
2199-
% bazel --host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.3.0.jar \
2199+
% bazel --host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.3.4.jar \
22002200
--host_jvm_args=-DRULE_MEMORY_TRACKER=1 \
22012201
dump --rules
22022202

22032203
# Dump Starlark heap and analyze it with pprof
2204-
% bazel --host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.3.0.jar \
2204+
% bazel --host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.3.4.jar \
22052205
--host_jvm_args=-DRULE_MEMORY_TRACKER=1 \
22062206
dump --skylark_memory=$HOME/prof.gz
22072207
% pprof -flame $HOME/prof.gz

site/en/rules/performance.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,13 @@ You must pass these two startup flags to *every* Bazel invocation:
225225

226226
```
227227
STARTUP_FLAGS=\
228-
--host_jvm_args=-javaagent:<path to java-allocation-instrumenter-3.3.0.jar> \
228+
--host_jvm_args=-javaagent:<path to java-allocation-instrumenter-3.3.4.jar> \
229229
--host_jvm_args=-DRULE_MEMORY_TRACKER=1
230230
```
231231
Note: You can download the allocation instrumenter jar file from [Maven Central
232232
Repository][allocation-instrumenter-link].
233233

234-
[allocation-instrumenter-link]: https://repo1.maven.org/maven2/com/google/code/java-allocation-instrumenter/java-allocation-instrumenter/3.3.0
234+
[allocation-instrumenter-link]: https://repo1.maven.org/maven2/com/google/code/java-allocation-instrumenter/java-allocation-instrumenter/3.3.4
235235

236236
These start the server in memory tracking mode. If you forget these for even
237237
one Bazel invocation the server will restart and you will have to start over.

src/main/java/com/google/devtools/build/lib/profiler/memory/AllocationTrackerModule.java

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
import com.google.devtools.build.lib.analysis.BlazeVersionInfo;
1919
import com.google.devtools.build.lib.analysis.ServerDirectories;
2020
import com.google.devtools.build.lib.clock.Clock;
21+
import com.google.devtools.build.lib.events.Event;
2122
import com.google.devtools.build.lib.runtime.BlazeModule;
2223
import com.google.devtools.build.lib.runtime.BlazeRuntime;
24+
import com.google.devtools.build.lib.runtime.CommandEnvironment;
2325
import com.google.devtools.build.lib.runtime.WorkspaceBuilder;
2426
import com.google.devtools.build.lib.vfs.FileSystem;
2527
import com.google.devtools.common.options.OptionsParsingResult;
@@ -36,7 +38,7 @@
3638
* <li>--host_jvm_args=-javaagent:(path to Google's java agent jar)
3739
* <ul>
3840
* <li>For Bazel use <a
39-
* href="https://github.com/bazelbuild/bazel/tree/master/third_party/allocation_instrumenter">java-allocation-instrumenter-3.3.0.jar</a>
41+
* href="https://github.com/bazelbuild/bazel/tree/master/third_party/allocation_instrumenter">java-allocation-instrumenter-3.3.4.jar</a>
4042
* </ul>
4143
* <li>--host_jvm_args=-DRULE_MEMORY_TRACKER=1
4244
* </ol>
@@ -55,7 +57,9 @@ public class AllocationTrackerModule extends BlazeModule {
5557
private static final int VARIANCE = 100;
5658

5759
private boolean enabled;
58-
private AllocationTracker tracker = null;
60+
// Always AllocationTracker, but we don't refer to the type as it is supplied manually via a Java
61+
// agent.
62+
private Object tracker = null;
5963

6064
@Override
6165
public void blazeStartup(
@@ -65,21 +69,43 @@ public void blazeStartup(
6569
FileSystem fileSystem,
6670
ServerDirectories directories,
6771
Clock clock) {
68-
String memoryTrackerPropery = System.getProperty("RULE_MEMORY_TRACKER");
69-
enabled = memoryTrackerPropery != null && memoryTrackerPropery.equals("1");
72+
enabled = isRequested();
7073
if (enabled) {
74+
try {
75+
Class.forName("com.google.monitoring.runtime.instrumentation.Sampler");
76+
} catch (ClassNotFoundException e) {
77+
enabled = false;
78+
return;
79+
}
7180
tracker = new AllocationTracker(SAMPLE_SIZE, VARIANCE);
72-
Debug.setThreadHook(tracker);
81+
Debug.setThreadHook((AllocationTracker) tracker);
7382
CurrentRuleTracker.setEnabled(true);
74-
AllocationTrackerInstaller.installAllocationTracker(tracker);
83+
AllocationTrackerInstaller.installAllocationTracker((AllocationTracker) tracker);
7584
}
7685
}
7786

7887
@Override
7988
public void workspaceInit(
8089
BlazeRuntime runtime, BlazeDirectories directories, WorkspaceBuilder builder) {
8190
if (enabled) {
82-
builder.setAllocationTracker(tracker);
91+
builder.setAllocationTracker((AllocationTracker) tracker);
8392
}
8493
}
94+
95+
@Override
96+
public void beforeCommand(CommandEnvironment env) {
97+
if (!enabled && isRequested()) {
98+
env.getReporter()
99+
.handle(
100+
Event.error(
101+
"Failed to enable memory tracking, ensure that you set"
102+
+ " --host_jvm_args=-javaagent:<path to"
103+
+ " java-allocation-instrumenter-3.3.4.jar>"));
104+
}
105+
}
106+
107+
private static boolean isRequested() {
108+
String memoryTrackerProperty = System.getProperty("RULE_MEMORY_TRACKER");
109+
return memoryTrackerProperty != null && memoryTrackerProperty.equals("1");
110+
}
85111
}

src/main/java/com/google/devtools/build/lib/profiler/memory/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ java_library(
2525
"//src/main/java/com/google/devtools/build/lib/analysis:blaze_version_info",
2626
"//src/main/java/com/google/devtools/build/lib/analysis:server_directories",
2727
"//src/main/java/com/google/devtools/build/lib/clock",
28+
"//src/main/java/com/google/devtools/build/lib/events",
2829
"//src/main/java/com/google/devtools/build/lib/vfs",
2930
"//src/main/java/com/google/devtools/common/options",
3031
"//src/main/java/net/starlark/java/eval",

src/test/java/com/google/devtools/build/lib/profiler/memory/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ filegroup(
1616
java_test(
1717
name = "AllocationTrackerTest",
1818
srcs = ["AllocationTrackerTest.java"],
19+
runtime_deps = ["//third_party/allocation_instrumenter:allocation_instrumenter_runtime"],
1920
deps = [
2021
"//src/main/java/com/google/devtools/build/lib/packages",
2122
"//src/main/java/com/google/devtools/build/lib/profiler/memory:allocationtracker",

src/test/java/com/google/devtools/common/options/OptionDefaultValueConversionTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public static List<OptionDefinition> getAllProdOptionDefinitions() {
6363

6464
List<OptionDefinition> optionDefinitions =
6565
allClasses.stream()
66+
// This package contains classes that reference other classes that aren't available
67+
// without manual setup.
68+
.filter(
69+
c -> !c.getPackageName().equals("com.google.devtools.build.lib.profiler.memory"))
6670
.filter(c -> !isTestClass(c))
6771
.flatMap(c -> Arrays.stream(c.getFields()))
6872
.filter(f -> f.isAnnotationPresent(Option.class))

src/test/shell/bazel/jdeps_test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ function test_jdeps() {
7777
|| fail "Failed to run jdeps on non denylisted class files."
7878
cd ..
7979

80+
# Keep java.instrument for allocation_instrumenter, which is supplied by the user.
81+
echo "java.instrument" >> jdeps
82+
8083
# Make the list sorted and unique and compare it with expected results.
8184
cat jdeps | \
8285
sed -e 's|[[:space:]]*||g' -e 's|/.*||' | \

third_party/allocation_instrumenter/BUILD

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("@rules_java//java:java_library.bzl", "java_library")
2+
13
package(default_visibility = ["//visibility:public"])
24

35
licenses(["notice"]) # Apache 2.0
@@ -9,5 +11,12 @@ filegroup(
911

1012
java_library(
1113
name = "allocation_instrumenter",
14+
neverlink = True,
15+
exports = ["@maven//:com_google_code_java_allocation_instrumenter_java_allocation_instrumenter"],
16+
)
17+
18+
java_library(
19+
name = "allocation_instrumenter_runtime",
20+
testonly = True,
1221
exports = ["@maven//:com_google_code_java_allocation_instrumenter_java_allocation_instrumenter"],
1322
)

0 commit comments

Comments
 (0)