Skip to content

Commit 708db87

Browse files
authored
[7.5.0] Remove allocation instrumenter jar and update version in docs (#24912)
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 #24782 Closes #24783. PiperOrigin-RevId: 714057306 Change-Id: Ic8d47562f15344ed16d0af5d3242937d2ee53b22 (cherry picked from commit b59fbee) Fixes #24788
1 parent eb361d4 commit 708db87

File tree

11 files changed

+89
-68
lines changed

11 files changed

+89
-68
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ maven.install(
9898
"com.google.auto.value:auto-value-annotations:1.11.0",
9999
"com.google.code.findbugs:jsr305:3.0.2",
100100
"com.google.code.gson:gson:2.9.0",
101-
"com.google.code.java-allocation-instrumenter:java-allocation-instrumenter:3.3.0",
101+
"com.google.code.java-allocation-instrumenter:java-allocation-instrumenter:3.3.4",
102102
"com.google.errorprone:error_prone_annotation:2.22.0",
103103
"com.google.errorprone:error_prone_annotations:2.22.0",
104104
"com.google.errorprone:error_prone_check_api:2.22.0",

MODULE.bazel.lock

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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": 1071623342,
4-
"__RESOLVED_ARTIFACTS_HASH": 1286859829,
3+
"__INPUT_ARTIFACTS_HASH": -669893718,
4+
"__RESOLVED_ARTIFACTS_HASH": -1421116745,
55
"conflict_resolution": {
66
"com.google.code.gson:gson:2.8.9": "com.google.code.gson:gson:2.9.0",
77
"com.google.errorprone:error_prone_annotations:2.3.2": "com.google.errorprone:error_prone_annotations:2.22.0",
@@ -122,9 +122,9 @@
122122
},
123123
"com.google.code.java-allocation-instrumenter:java-allocation-instrumenter": {
124124
"shasums": {
125-
"jar": "1ef5535a8bd41cf3072469f381b9ee6ab28275311a7499f53d6e52adf976fef0"
125+
"jar": "44f8cddec129520b2532fa9ff25f9572d7566307d660635ba32bf409f06ae336"
126126
},
127-
"version": "3.3.0"
127+
"version": "3.3.4"
128128
},
129129
"com.google.errorprone:error_prone_annotation": {
130130
"shasums": {
@@ -824,15 +824,6 @@
824824
"com.google.auto:auto-common": [
825825
"com.google.guava:guava"
826826
],
827-
"com.google.code.java-allocation-instrumenter:java-allocation-instrumenter": [
828-
"com.google.guava:guava",
829-
"javax.annotation:javax.annotation-api",
830-
"org.ow2.asm:asm",
831-
"org.ow2.asm:asm-analysis",
832-
"org.ow2.asm:asm-commons",
833-
"org.ow2.asm:asm-tree",
834-
"org.ow2.asm:asm-util"
835-
],
836827
"com.google.errorprone:error_prone_annotation": [
837828
"com.google.guava:guava"
838829
],
@@ -1417,30 +1408,16 @@
14171408
"com.google.monitoring.runtime.instrumentation.asm.commons",
14181409
"com.google.monitoring.runtime.instrumentation.asm.signature",
14191410
"com.google.monitoring.runtime.instrumentation.asm.tree",
1420-
"com.google.monitoring.runtime.instrumentation.asm.tree.analysis",
1421-
"com.google.monitoring.runtime.instrumentation.asm.util",
1422-
"com.google.monitoring.runtime.instrumentation.checker.nullness.compatqual",
1423-
"com.google.monitoring.runtime.instrumentation.common.annotations",
1424-
"com.google.monitoring.runtime.instrumentation.common.base",
1425-
"com.google.monitoring.runtime.instrumentation.common.base.internal",
1426-
"com.google.monitoring.runtime.instrumentation.common.cache",
1427-
"com.google.monitoring.runtime.instrumentation.common.collect",
1428-
"com.google.monitoring.runtime.instrumentation.common.escape",
1429-
"com.google.monitoring.runtime.instrumentation.common.eventbus",
1430-
"com.google.monitoring.runtime.instrumentation.common.graph",
1431-
"com.google.monitoring.runtime.instrumentation.common.hash",
1432-
"com.google.monitoring.runtime.instrumentation.common.html",
1433-
"com.google.monitoring.runtime.instrumentation.common.io",
1434-
"com.google.monitoring.runtime.instrumentation.common.math",
1435-
"com.google.monitoring.runtime.instrumentation.common.net",
1436-
"com.google.monitoring.runtime.instrumentation.common.primitives",
1437-
"com.google.monitoring.runtime.instrumentation.common.reflect",
1438-
"com.google.monitoring.runtime.instrumentation.common.util.concurrent",
1439-
"com.google.monitoring.runtime.instrumentation.common.xml",
1440-
"com.google.monitoring.runtime.instrumentation.errorprone.annotations",
1441-
"com.google.monitoring.runtime.instrumentation.errorprone.annotations.concurrent",
1442-
"com.google.monitoring.runtime.instrumentation.j2objc.annotations",
1443-
"com.google.thirdparty.publicsuffix"
1411+
"com.google.monitoring.runtime.instrumentation.common.com.google.common.annotations",
1412+
"com.google.monitoring.runtime.instrumentation.common.com.google.common.base",
1413+
"com.google.monitoring.runtime.instrumentation.common.com.google.common.cache",
1414+
"com.google.monitoring.runtime.instrumentation.common.com.google.common.collect",
1415+
"com.google.monitoring.runtime.instrumentation.common.com.google.common.math",
1416+
"com.google.monitoring.runtime.instrumentation.common.com.google.common.primitives",
1417+
"com.google.monitoring.runtime.instrumentation.common.com.google.common.util.concurrent",
1418+
"com.google.monitoring.runtime.instrumentation.common.com.google.common.util.concurrent.internal",
1419+
"javax.annotation",
1420+
"javax.annotation.security"
14441421
],
14451422
"com.google.errorprone:error_prone_annotation": [
14461423
"com.google.errorprone"

site/en/docs/user-manual.md

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

2185-
* `--host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.3.0.jar`
2185+
* `--host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.3.4.jar`
21862186
* `--host_jvm_args=-DRULE_MEMORY_TRACKER=1`
21872187

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

21922192
Do not forget to keep passing these options to Bazel for every command or the server will
21932193
restart.
21942194

21952195
Example:
21962196

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

22022202
# Dump rules
2203-
% bazel --host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.3.0.jar \
2203+
% bazel --host_jvm_args=-javaagent:$BAZEL/third_party/allocation_instrumenter/java-allocation-instrumenter-3.3.4.jar \
22042204
--host_jvm_args=-DRULE_MEMORY_TRACKER=1 \
22052205
dump --rules
22062206

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

site/en/rules/performance.md

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

219219
```
220220
STARTUP_FLAGS=\
221-
--host_jvm_args=-javaagent:<path to java-allocation-instrumenter-3.3.0.jar> \
221+
--host_jvm_args=-javaagent:<path to java-allocation-instrumenter-3.3.4.jar> \
222222
--host_jvm_args=-DRULE_MEMORY_TRACKER=1
223223
```
224224
Note: You can download the allocation instrumenter jar file from [Maven Central
225225
Repository][allocation-instrumenter-link].
226226

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

229229
These start the server in memory tracking mode. If you forget these for even
230230
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
@@ -78,6 +78,9 @@ function test_jdeps() {
7878
|| fail "Failed to run jdeps on non denylisted class files."
7979
cd ..
8080

81+
# Keep java.instrument for allocation_instrumenter, which is supplied by the user.
82+
echo "java.instrument" >> jdeps
83+
8184
# Make the list sorted and unique and compare it with expected results.
8285
cat jdeps | \
8386
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)