Skip to content

Commit 3cb87b4

Browse files
jbachorikclaude
andcommitted
Fix live heap enablement logic for Java 8 and unsafe JVM versions
- On Java 8, neither ddprof MEMLEAK (requires Java 11+) nor JFR OldObjectSample is available; explicitly enabling profiling.heap.enabled now logs a warning instead of silently enabling an unsupported event - ddprofLikelyActive heuristic uses isJmethodIDSafe() as the default for the liveheap flag (was hardcoded true), matching ddprof's own resolution and preventing false disablement of OldObjectSample on Java 11.0.12-11.0.22 and 17.0.3-17.0.10 - Fix testHeapProfilerIsStillOverriddenThroughConfig to expect isOldObjectSampleAvailable() instead of unconditional true Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 749172f commit 3cb87b4

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

dd-java-agent/agent-profiling/profiling-controller-openjdk/src/main/java/com/datadog/profiling/controller/openjdk/OpenJdkController.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,25 @@ ProfilingConfig.PROFILING_HEAP_ENABLED, isLiveHeapProfilingSafe())) {
202202
disableEvent(recordingSettings, "jdk.OldObjectSample", "live heap profiling is disabled");
203203
} else {
204204
// ddprof live heap requires Java 11+ (JVMTI Allocation Sampler)
205+
// isJmethodIDSafe() matches ddprof's own default for liveheap: it only enables
206+
// MEMLEAK mode by default on versions where jmethodID is safe.
205207
boolean ddprofLikelyActive =
206208
isJavaVersionAtLeast(11)
207209
&& configProvider.getBoolean(
208-
ProfilingConfig.PROFILING_DATADOG_PROFILER_LIVEHEAP_ENABLED, true)
210+
ProfilingConfig.PROFILING_DATADOG_PROFILER_LIVEHEAP_ENABLED, isJmethodIDSafe())
209211
&& configProvider.getBoolean(
210212
ProfilingConfig.PROFILING_DATADOG_PROFILER_ENABLED, true);
211213
if (ddprofLikelyActive) {
212214
disableEvent(
213215
recordingSettings,
214216
"jdk.OldObjectSample",
215217
"ddprof live heap profiling is expected to handle live heap data");
218+
} else if (isOldObjectSampleAvailable()) {
219+
enableEvent(recordingSettings, "jdk.OldObjectSample", "heap profiling is enabled");
220+
} else if (configProvider.getBoolean(ProfilingConfig.PROFILING_HEAP_ENABLED, false)) {
221+
log.warn(
222+
"Live heap profiling was explicitly requested but is not supported on this JVM version;"
223+
+ " no heap profiling data will be collected.");
216224
}
217225
}
218226

dd-java-agent/agent-profiling/profiling-controller-openjdk/src/test/java/com/datadog/profiling/controller/openjdk/OpenJdkControllerTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,11 @@ public void testHeapProfilerIsStillOverriddenThroughConfig() throws Exception {
106106
((OpenJdkRecordingData)
107107
controller.createRecording(TEST_NAME, new ControllerContext().snapshot()).stop())
108108
.getRecording()) {
109+
// On JVMs where OldObjectSample is not available (e.g. Java 8), explicitly enabling heap
110+
// profiling has no effect — the event cannot be safely enabled.
109111
assertEquals(
110-
true, Boolean.parseBoolean(recording.getSettings().get("jdk.OldObjectSample#enabled")));
112+
isOldObjectSampleAvailable(),
113+
Boolean.parseBoolean(recording.getSettings().get("jdk.OldObjectSample#enabled")));
111114
}
112115
}
113116

0 commit comments

Comments
 (0)