Skip to content

Commit c87737e

Browse files
jbachorikclaude
andcommitted
fix(asan): apply heap fix unconditionally, not just for JDK 25
The shadow-memory conflict is ASLR-dependent, not JDK-version specific. JDK 17 hits the same 0x7fff7000 placement on some kernel configurations. Remove the >= 25 version gate so all ASan test runs get the low heap base. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 0738808 commit c87737e

2 files changed

Lines changed: 12 additions & 31 deletions

File tree

build-logic/conventions/src/main/kotlin/com/datadoghq/native/config/ConfigurationPresets.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,18 @@ object ConfigurationPresets {
215215
put("UBSAN_OPTIONS", "halt_on_error=0:abort_on_error=0:print_stacktrace=1:suppressions=$rootDir/gradle/sanitizers/ubsan.supp")
216216
put("LSAN_OPTIONS", "detect_leaks=0")
217217
}
218-
// JDK 25's G1GC reserves heap virtual address space starting just below 2 GB
219-
// (0x7fff7000), which is exactly where ASan needs to mmap its shadow bytes
220-
// [0x7fff7000-0x10007fff7fff]. Force the heap to a very low base address so
221-
// the entire JVM footprint (heap + class space + code cache) stays well below
222-
// the shadow range and the two regions no longer conflict.
223-
if (PlatformUtils.testJvmMajorVersion() >= 25) {
224-
config.testJvmArgs.addAll(listOf(
225-
"-XX:HeapBaseMinAddress=0x4000000",
226-
"-Xmx512m",
227-
"-XX:CompressedClassSpaceSize=256m"
228-
))
229-
}
218+
// G1GC's heap reservation is placed just below 2 GB (0x7fff7000) by ASLR on
219+
// some kernel configurations, which is exactly where ASan needs to mmap its
220+
// shadow bytes [0x7fff7000-0x10007fff7fff]. This is not JDK-version specific
221+
// — it depends on the kernel's mmap base randomisation at the time the process
222+
// starts. Force the heap to a very low base address so the entire JVM
223+
// footprint (heap + class space + code cache) stays well below the shadow
224+
// range and the two regions never conflict.
225+
config.testJvmArgs.addAll(listOf(
226+
"-XX:HeapBaseMinAddress=0x4000000",
227+
"-Xmx512m",
228+
"-XX:CompressedClassSpaceSize=256m"
229+
))
230230
}
231231
}
232232
Platform.MACOS -> {

build-logic/conventions/src/main/kotlin/com/datadoghq/native/util/PlatformUtils.kt

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -368,23 +368,4 @@ object PlatformUtils {
368368
}
369369
}
370370

371-
/**
372-
* Returns the major version of the test JVM (e.g. 8, 11, 17, 21, 25).
373-
* Returns 0 if the version cannot be determined.
374-
*/
375-
fun testJvmMajorVersion(): Int {
376-
val javaHome = testJavaHome()
377-
return try {
378-
val process = ProcessBuilder("$javaHome/bin/java", "-version")
379-
.redirectErrorStream(true)
380-
.start()
381-
val output = process.inputStream.bufferedReader().readText()
382-
process.waitFor(10, TimeUnit.SECONDS)
383-
// version line: java version "1.8.0_xxx" or java version "21.0.x" etc.
384-
val match = Regex("""version "(?:1\.)?(\d+)""").find(output)
385-
match?.groupValues?.get(1)?.toIntOrNull() ?: 0
386-
} catch (_: Exception) {
387-
0
388-
}
389-
}
390371
}

0 commit comments

Comments
 (0)