Skip to content

Commit 9ef1d89

Browse files
jbachorikclaude
andcommitted
Guard chaos harness malloc checking and gate hotspot in raw-pointer test
Detect glibc >= 2.34 and preload libc_malloc_debug (or fail clearly) so MALLOC_CHECK_ actually takes effect; check patch-dd-java-agent.sh's exit status directly instead of inferring success from JAR presence; force Hotspot on in FalseForRawAsgctBciWithBit30SetButNoEncodedMarker so the test exercises isRawPointer()'s HotSpot-gated path. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 8c1402d commit 9ef1d89

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

ddprof-lib/src/test/cpp/frame_ut.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ TEST(FrameTypeIsRawPointerTest, FalseForRawAsgctBciWithBit30SetButNoEncodedMarke
182182
// and therefore never set ENCODED_MASK; only encode(..., rawPointer=true)
183183
// (HotSpot-only, per its own assert) is allowed to set RAW_POINTER_MASK.
184184
int rawAsgctBciWithBit30 = 1 << 30;
185+
VMHotspotGuard hotspot(true);
185186
EXPECT_FALSE(FrameType::isRawPointer(rawAsgctBciWithBit30))
186187
<< "isRawPointer() must require ENCODED_MASK (bit 20) before trusting bit 30, "
187188
<< "otherwise raw ASGCT BCIs that never went through encode() can false-positive";

utils/run-chaos-harness.sh

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,15 @@ fi
123123
# Patch dd-java-agent.jar with the locally built ddprof contents so the
124124
# agent's (relocated) profiler classes match the version under test.
125125
PATCHED_AGENT="${WORK_DIR}/dd-java-agent-patched.jar"
126-
DD_AGENT_JAR="${DD_AGENT_JAR}" DDPROF_JAR="${DDPROF_JAR}" OUTPUT_JAR="${PATCHED_AGENT}" \
127-
"${ROOT}/utils/patch-dd-java-agent.sh"
128-
if [ ! -f "${PATCHED_AGENT}" ]; then
126+
if ! DD_AGENT_JAR="${DD_AGENT_JAR}" DDPROF_JAR="${DDPROF_JAR}" OUTPUT_JAR="${PATCHED_AGENT}" \
127+
"${ROOT}/utils/patch-dd-java-agent.sh"; then
129128
echo "FAIL:dd-java-agent patching failed" >&2
130129
exit 1
131130
fi
131+
if [ ! -f "${PATCHED_AGENT}" ]; then
132+
echo "FAIL:dd-java-agent patching reported success but output jar is missing" >&2
133+
exit 1
134+
fi
132135

133136
case $CONFIG in
134137
profiler)
@@ -163,6 +166,23 @@ case $ALLOCATOR in
163166
# (mirrors the tcmalloc/jemalloc tuning below).
164167
export MALLOC_ARENA_MAX=2
165168
export MALLOC_TRIM_THRESHOLD_=65536
169+
# glibc >= 2.34 moved MALLOC_CHECK_ support out of the main libc; it is a
170+
# silent no-op unless libc_malloc_debug is preloaded (see glibc's "Heap
171+
# Consistency Checking" docs). Detect that case and preload the debug
172+
# library explicitly, rather than silently running with corruption
173+
# detection disabled.
174+
if command -v ldd >/dev/null 2>&1; then
175+
GLIBC_VERSION=$(ldd --version 2>/dev/null | head -1 | grep -oE '[0-9]+\.[0-9]+$')
176+
if [ -n "${GLIBC_VERSION}" ] && [ "$(printf '%s\n' "2.34" "${GLIBC_VERSION}" | sort -V | head -1)" = "2.34" ]; then
177+
MALLOC_DEBUG_LIB=$(find /usr/lib/ /usr/lib64/ /lib/ /lib64/ -name 'libc_malloc_debug.so*' 2>/dev/null | head -1)
178+
if [ -z "${MALLOC_DEBUG_LIB}" ]; then
179+
echo "FAIL:glibc ${GLIBC_VERSION} requires libc_malloc_debug to be preloaded for MALLOC_CHECK_ to take effect, but it could not be found" >&2
180+
exit 1
181+
fi
182+
export LD_PRELOAD="${MALLOC_DEBUG_LIB}${LD_PRELOAD:+:${LD_PRELOAD}}"
183+
echo "glibc ${GLIBC_VERSION} detected — preloading ${MALLOC_DEBUG_LIB} for MALLOC_CHECK_"
184+
fi
185+
fi
166186
;;
167187
tcmalloc)
168188
export LD_PRELOAD=$(find /usr/lib/ /usr/lib64/ /opt/homebrew/lib/ /usr/local/lib/ -name 'libtcmalloc_minimal.so.4' -o -name 'libtcmalloc.dylib' 2>/dev/null | head -1)

0 commit comments

Comments
 (0)